Mercurial > emacs
annotate lisp/calc/calc-units.el @ 55694:62803bbfc576
(byte-compile-log): Use backquotes.
(byte-compile-log-1): Don't call (byte-goto-log-buffer).
Use with-current-buffer.
(byte-goto-log-buffer): Delete.
(byte-compile-log-file): Call compilation-forget-errors.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 19 May 2004 18:53:13 +0000 |
parents | 695cf19ef79e |
children | d8cdadecaba8 375f2633d815 |
rev | line source |
---|---|
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1 ;;; calc-units.el --- unit conversion functions for Calc |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
2 |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
4 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
6 ;; Maintainers: D. Goel <deego@gnufans.org> |
49263
f4d68f97221e
Add new maintainer (deego).
Deepak Goel <deego@gnufans.org>
parents:
45291
diff
changeset
|
7 ;; Colin Walters <walters@debian.org> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
16 ;; License for full details. | |
17 | |
18 ;; Everyone is granted permission to copy, modify and redistribute | |
19 ;; GNU Emacs, but only under the conditions described in the | |
20 ;; GNU Emacs General Public License. A copy of this license is | |
21 ;; supposed to have been given to you along with GNU Emacs so you | |
22 ;; can know your rights and responsibilities. It should be in a | |
23 ;; file named COPYING. Among other things, the copyright notice | |
24 ;; and this notice must be preserved on all copies. | |
25 | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; This file is autoloaded from calc-ext.el. | |
31 (require 'calc-ext) | |
32 | |
33 (require 'calc-macs) | |
34 | |
35 (defun calc-Need-calc-units () nil) | |
36 | |
37 ;;; Units operations. | |
38 | |
39 ;;; Units table last updated 9-Jan-91 by Ulrich Mueller (ulm@vsnhd1.cern.ch) | |
40 ;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov) | |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
41 ;;; Updated April 2002 by Jochen Küpper |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
42 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
43 ;;; for CODATA 1998 see one of |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
44 ;;; - Journal of Physical and Chemical Reference Data, 28(6), 1713-1852, 1999. |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
45 ;;; - Reviews of Modern Physics, 72(2), 351-495, 2000. |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
46 ;;; - http://physics.nist.gov/cuu/Constants/index.html |
40785 | 47 |
48 (defvar math-standard-units | |
49 '( ;; Length | |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
50 ( m nil "*Meter" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
51 ( in "2.54 cm" "Inch" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
52 ( ft "12 in" "Foot" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
53 ( yd "3 ft" "Yard" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
54 ( mi "5280 ft" "Mile" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
55 ( au "149597870691 m" "Astronomical Unit" ) ;; NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
56 ( lyr "9460536207068016 m" "Light Year" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
57 ( pc "206264.80625 au" "Parsec" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
58 ( nmi "1852 m" "Nautical Mile" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
59 ( fath "6 ft" "Fathom" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
60 ( u "1 um" "Micron" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
61 ( mil "in/1000" "Mil" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
62 ( point "in/72" "Point (1/72 inch)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
63 ( tpt "in/72.27" "Point (TeX conventions)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
64 ( Ang "1e-10 m" "Angstrom" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
65 ( mfi "mi+ft+in" "Miles + feet + inches" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
66 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
67 ;; Area |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
68 ( hect "10000 m^2" "*Hectare" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
69 ( acre "mi^2 / 640" "Acre" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
70 ( b "1e-28 m^2" "Barn" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
71 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
72 ;; Volume |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
73 ( l "1e-3 m^3" "*Liter" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
74 ( L "1e-3 m^3" "Liter" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
75 ( gal "4 qt" "US Gallon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
76 ( qt "2 pt" "Quart" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
77 ( pt "2 cup" "Pint" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
78 ( cup "8 ozfl" "Cup" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
79 ( ozfl "2 tbsp" "Fluid Ounce" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
80 ( floz "2 tbsp" "Fluid Ounce" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
81 ( tbsp "3 tsp" "Tablespoon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
82 ( tsp "4.92892159375 ml" "Teaspoon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
83 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
84 ( galC "4.54609 l" "Canadian Gallon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
85 ( galUK "4.546092 l" "UK Gallon" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
86 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
87 ;; Time |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
88 ( s nil "*Second" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
89 ( sec "s" "Second" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
90 ( min "60 s" "Minute" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
91 ( hr "60 min" "Hour" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
92 ( day "24 hr" "Day" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
93 ( wk "7 day" "Week" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
94 ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
95 ( yr "365.25 day" "Year" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
96 ( Hz "1/s" "Hertz" ) |
40785 | 97 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
98 ;; Speed |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
99 ( mph "mi/hr" "*Miles per hour" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
100 ( kph "km/hr" "Kilometers per hour" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
101 ( knot "nmi/hr" "Knot" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
102 ( c "2.99792458e8 m/s" "Speed of light" ) |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
103 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
104 ;; Acceleration |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
105 ( ga "9.80665 m/s^2" "*\"g\" acceleration" ) |
40785 | 106 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
107 ;; Mass |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
108 ( g nil "*Gram" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
109 ( lb "16 oz" "Pound (mass)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
110 ( oz "28.349523125 g" "Ounce (mass)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
111 ( ton "2000 lb" "Ton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
112 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
113 ( t "1000 kg" "Metric ton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
114 ( tonUK "1016.0469088 kg" "UK ton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
115 ( lbt "12 ozt" "Troy pound" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
116 ( ozt "31.103475 g" "Troy ounce" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
117 ( ct ".2 g" "Carat" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
118 ( amu "1.66053873e-27 kg" "Unified atomic mass" ) ;; CODATA 1998 |
40785 | 119 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
120 ;; Force |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
121 ( N "m kg/s^2" "*Newton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
122 ( dyn "1e-5 N" "Dyne" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
123 ( gf "ga g" "Gram (force)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
124 ( lbf "4.44822161526 N" "Pound (force)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
125 ( kip "1000 lbf" "Kilopound (force)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
126 ( pdl "0.138255 N" "Poundal" ) |
40785 | 127 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
128 ;; Energy |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
129 ( J "N m" "*Joule" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
130 ( erg "1e-7 J" "Erg" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
131 ( cal "4.1868 J" "International Table Calorie" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
132 ( Btu "1055.05585262 J" "International Table Btu" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
133 ( eV "ech V" "Electron volt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
134 ( ev "eV" "Electron volt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
135 ( therm "105506000 J" "EEC therm" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
136 ( invcm "h c/cm" "Energy in inverse centimeters" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
137 ( Kayser "invcm" "Kayser (inverse centimeter energy)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
138 ( men "100/invcm" "Inverse energy in meters" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
139 ( Hzen "h Hz" "Energy in Hertz") |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
140 ( Ken "k K" "Energy in Kelvins") |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
141 ( Wh "W h" "Watt hour") |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
142 ( Ws "W s" "Watt second") |
40785 | 143 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
144 ;; Power |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
145 ( W "J/s" "*Watt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
146 ( hp "745.7 W" "Horsepower" ) |
40785 | 147 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
148 ;; Temperature |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
149 ( K nil "*Degree Kelvin" K ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
150 ( dK "K" "Degree Kelvin" K ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
151 ( degK "K" "Degree Kelvin" K ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
152 ( dC "K" "Degree Celsius" C ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
153 ( degC "K" "Degree Celsius" C ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
154 ( dF "(5/9) K" "Degree Fahrenheit" F ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
155 ( degF "(5/9) K" "Degree Fahrenheit" F ) |
40785 | 156 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
157 ;; Pressure |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
158 ( Pa "N/m^2" "*Pascal" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
159 ( bar "1e5 Pa" "Bar" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
160 ( atm "101325 Pa" "Standard atmosphere" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
161 ( torr " 1.333224e2 Pa" "Torr" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
162 ( mHg "1000 torr" "Meter of mercury" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
163 ( inHg "25.4 mmHg" "Inch of mercury" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
164 ( inH2O "2.490889e2 Pa" "Inch of water" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
165 ( psi "6894.75729317 Pa" "Pound per square inch" ) |
40785 | 166 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
167 ;; Viscosity |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
168 ( P "0.1 Pa s" "*Poise" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
169 ( St "1e-4 m^2/s" "Stokes" ) |
40785 | 170 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
171 ;; Electromagnetism |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
172 ( A nil "*Ampere" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
173 ( C "A s" "Coulomb" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
174 ( Fdy "ech Nav" "Faraday" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
175 ( e "1.602176462e-19 C" "Elementary charge" ) ;; CODATA 1998 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
176 ( ech "1.602176462e-19 C" "Elementary charge" ) ;; CODATA 1998 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
177 ( V "W/A" "Volt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
178 ( ohm "V/A" "Ohm" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
179 ( mho "A/V" "Mho" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
180 ( S "A/V" "Siemens" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
181 ( F "C/V" "Farad" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
182 ( H "Wb/A" "Henry" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
183 ( T "Wb/m^2" "Tesla" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
184 ( G "1e-4 T" "Gauss" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
185 ( Wb "V s" "Weber" ) |
40785 | 186 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
187 ;; Luminous intensity |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
188 ( cd nil "*Candela" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
189 ( sb "1e4 cd/m^2" "Stilb" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
190 ( lm "cd sr" "Lumen" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
191 ( lx "lm/m^2" "Lux" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
192 ( ph "1e4 lx" "Phot" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
193 ( fc "10.76391 lx" "Footcandle" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
194 ( lam "1e4 lm/m^2" "Lambert" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
195 ( flam "3.426259 cd/m^2" "Footlambert" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
40785 | 196 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
197 ;; Radioactivity |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
198 ( Bq "1/s" "*Becquerel" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
199 ( Ci "3.7e10 Bq" "Curie" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
200 ( Gy "J/kg" "Gray" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
201 ( Sv "Gy" "Sievert" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
202 ( R "2.58e-4 C/kg" "Roentgen" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
203 ( rd ".01 Gy" "Rad" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
204 ( rem "rd" "Rem" ) |
40785 | 205 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
206 ;; Amount of substance |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
207 ( mol nil "*Mole" ) |
40785 | 208 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
209 ;; Plane angle |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
210 ( rad nil "*Radian" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
211 ( circ "2 pi rad" "Full circle" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
212 ( rev "circ" "Full revolution" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
213 ( deg "circ/360" "Degree" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
214 ( arcmin "deg/60" "Arc minute" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
215 ( arcsec "arcmin/60" "Arc second" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
216 ( grad "circ/400" "Grade" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
217 ( rpm "rev/min" "Revolutions per minute" ) |
40785 | 218 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
219 ;; Solid angle |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
220 ( sr nil "*Steradian" ) |
40785 | 221 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
222 ;; Other physical quantities (CODATA 1998) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
223 ( h "6.62606876e-34 J s" "*Planck's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
224 ( hbar "h / 2 pi" "Planck's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
225 ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
226 ( Grav "6.673e-11 m^3/kg^1/s^2" "Gravitational constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
227 ( Nav "6.02214199e23 / mol" "Avagadro's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
228 ( me "9.10938188e-31 kg" "Electron rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
229 ( mp "1.67262158e-27 kg" "Proton rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
230 ( mn "1.67492716e-27 kg" "Neutron rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
231 ( mu "1.88353109e-28 kg" "Muon rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
232 ( Ryd "10973731.568549 /m" "Rydberg's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
233 ( k "1.3806503e-23 J/K" "Boltzmann's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
234 ( fsc "7.297352533e-3" "Fine structure constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
235 ( muB "927.400899e-26 J/T" "Bohr magneton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
236 ( muN "5.05078317e-27 J/T" "Nuclear magneton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
237 ( mue "-928.476362e-26 J/T" "Electron magnetic moment" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
238 ( mup "1.410606633e-26 J/T" "Proton magnetic moment" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
239 ( R0 "8.314472 J/mol/K" "Molar gas constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
240 ( V0 "22.710981e-3 m^3/mol" "Standard volume of ideal gas" ))) |
40785 | 241 |
242 | |
243 (defvar math-additional-units nil | |
244 "*Additional units table for user-defined units. | |
245 Must be formatted like math-standard-units. | |
246 If this is changed, be sure to set math-units-table to nil to ensure | |
247 that the combined units table will be rebuilt.") | |
248 | |
249 (defvar math-unit-prefixes | |
250 '( ( ?E (float 1 18) "Exa" ) | |
251 ( ?P (float 1 15) "Peta" ) | |
252 ( ?T (float 1 12) "Tera" ) | |
253 ( ?G (float 1 9) "Giga" ) | |
254 ( ?M (float 1 6) "Mega" ) | |
255 ( ?k (float 1 3) "Kilo" ) | |
256 ( ?K (float 1 3) "Kilo" ) | |
257 ( ?h (float 1 2) "Hecto" ) | |
258 ( ?H (float 1 2) "Hecto" ) | |
259 ( ?D (float 1 1) "Deka" ) | |
260 ( 0 (float 1 0) nil ) | |
261 ( ?d (float 1 -1) "Deci" ) | |
262 ( ?c (float 1 -2) "Centi" ) | |
263 ( ?m (float 1 -3) "Milli" ) | |
264 ( ?u (float 1 -6) "Micro" ) | |
265 ( ?n (float 1 -9) "Nano" ) | |
266 ( ?p (float 1 -12) "Pico" ) | |
267 ( ?f (float 1 -15) "Femto" ) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
268 ( ?a (float 1 -18) "Atto" ))) |
40785 | 269 |
270 (defvar math-standard-units-systems | |
271 '( ( base nil ) | |
272 ( si ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) ) | |
273 ( mks ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) ) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
274 ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) ))) |
40785 | 275 |
276 (defvar math-units-table nil | |
277 "Internal units table derived from math-defined-units. | |
278 Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |
279 | |
280 (defvar math-units-table-buffer-valid nil) | |
281 | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
282 ;;; Units commands. |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
283 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
284 (defun calc-base-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
285 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
286 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
287 (let ((calc-autorange-units nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
288 (calc-enter-result 1 "bsun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
289 (math-to-standard-units (calc-top-n 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
290 nil)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
291 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
292 (defun calc-quick-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
293 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
294 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
295 (let* ((num (- last-command-char ?0)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
296 (pos (if (= num 0) 10 num)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
297 (units (calc-var-value 'var-Units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
298 (expr (calc-top-n 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
299 (unless (and (>= num 0) (<= num 9)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
300 (errunless "Bad unit number")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
301 (unless (math-vectorp units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
302 (errunless "No \"quick units\" are defined")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
303 (unless (< pos (length units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
304 (errunless "Unit number %d not defined" pos)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
305 (if (math-units-in-expr-p expr nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
306 (calc-enter-result 1 (format "cun%d" num) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
307 (math-convert-units expr (nth pos units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
308 (calc-enter-result 1 (format "*un%d" num) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
309 (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
310 (math-mul expr (nth pos units)))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
311 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
312 (defun calc-convert-units (&optional old-units new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
313 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
314 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
315 (let ((expr (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
316 (uoldname nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
317 unew) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
318 (unless (math-units-in-expr-p expr t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
319 (let ((uold (or old-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
320 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
321 (setq uoldname (read-string "Old units: ")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
322 (if (equal uoldname "") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
323 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
324 (setq uoldname "1") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
325 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
326 (if (string-match "\\` */" uoldname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
327 (setq uoldname (concat "1" uoldname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
328 (math-read-expr uoldname)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
329 (when (eq (car-safe uold) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
330 (error "Bad format in units expression: %s" (nth 1 uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
331 (setq expr (math-mul expr uold)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
332 (unless new-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
333 (setq new-units (read-string (if uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
334 (concat "Old units: " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
335 uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
336 ", new units: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
337 "New units: ")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
338 (when (string-match "\\` */" new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
339 (setq new-units (concat "1" new-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
340 (setq units (math-read-expr new-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
341 (when (eq (car-safe units) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
342 (error "Bad format in units expression: %s" (nth 2 units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
343 (let ((unew (math-units-in-expr-p units t)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
344 (std (and (eq (car-safe units) 'var) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
345 (assq (nth 1 units) math-standard-units-systems)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
346 (if std |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
347 (calc-enter-result 1 "cvun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
348 (math-to-standard-units expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
349 (nth 1 std)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
350 (unless unew |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
351 (error "No units specified")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
352 (calc-enter-result 1 "cvun" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
353 (math-convert-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
354 expr units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
355 (and uoldname (not (equal uoldname "1")))))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
356 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
357 (defun calc-autorange-units (arg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
358 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
359 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
360 (calc-change-mode 'calc-autorange-units arg nil t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
361 (message (if calc-autorange-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
362 "Adjusting target unit prefix automatically" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
363 "Using target units exactly")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
364 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
365 (defun calc-convert-temperature (&optional old-units new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
366 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
367 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
368 (let ((expr (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
369 (uold nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
370 (uoldname nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
371 unew) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
372 (setq uold (or old-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
373 (let ((units (math-single-units-in-expr-p expr))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
374 (if units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
375 (if (consp units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
376 (list 'var (car units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
377 (intern (concat "var-" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
378 (symbol-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
379 (car units))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
380 (error "Not a pure temperature expression")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
381 (math-read-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
382 (setq uoldname (read-string |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
383 "Old temperature units: "))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
384 (when (eq (car-safe uold) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
385 (error "Bad format in units expression: %s" (nth 2 uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
386 (or (math-units-in-expr-p expr nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
387 (setq expr (math-mul expr uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
388 (setq unew (or new-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
389 (math-read-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
390 (read-string (if uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
391 (concat "Old temperature units: " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
392 uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
393 ", new units: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
394 "New temperature units: "))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
395 (when (eq (car-safe unew) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
396 (error "Bad format in units expression: %s" (nth 2 unew))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
397 (calc-enter-result 1 "cvtm" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
398 (math-convert-temperature expr uold unew |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
399 uoldname)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
400 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
401 (defun calc-remove-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
402 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
403 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
404 (calc-enter-result 1 "rmun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
405 (math-remove-units (calc-top-n 1)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
406 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
407 (defun calc-extract-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
408 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
409 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
410 (calc-enter-result 1 "rmun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
411 (math-extract-units (calc-top-n 1)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
412 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
413 (defun calc-explain-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
414 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
415 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
416 (let ((num-units nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
417 (den-units nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
418 (calc-explain-units-rec (calc-top-n 1) 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
419 (and den-units (string-match "^[^(].* .*[^)]$" den-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
420 (setq den-units (concat "(" den-units ")"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
421 (if num-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
422 (if den-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
423 (message "%s per %s" num-units den-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
424 (message "%s" num-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
425 (if den-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
426 (message "1 per %s" den-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
427 (message "No units in expression")))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
428 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
429 (defun calc-explain-units-rec (expr pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
430 (let ((u (math-check-unit-name expr)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
431 pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
432 (if (and u (not (math-zerop pow))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
433 (let ((name (or (nth 2 u) (symbol-name (car u))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
434 (if (eq (aref name 0) ?\*) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
435 (setq name (substring name 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
436 (if (string-match "[^a-zA-Z0-9']" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
437 (if (string-match "^[a-zA-Z0-9' ()]*$" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
438 (while (setq pos (string-match "[ ()]" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
439 (setq name (concat (substring name 0 pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
440 (if (eq (aref name pos) 32) "-" "") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
441 (substring name (1+ pos))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
442 (setq name (concat "(" name ")")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
443 (or (eq (nth 1 expr) (car u)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
444 (setq name (concat (nth 2 (assq (aref (symbol-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
445 (nth 1 expr)) 0) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
446 math-unit-prefixes)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
447 (if (and (string-match "[^a-zA-Z0-9']" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
448 (not (memq (car u) '(mHg gf)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
449 (concat "-" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
450 (downcase name))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
451 (cond ((or (math-equal-int pow 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
452 (math-equal-int pow -1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
453 ((or (math-equal-int pow 2) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
454 (math-equal-int pow -2)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
455 (if (equal (nth 4 u) '((m . 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
456 (setq name (concat "Square-" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
457 (setq name (concat name "-squared")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
458 ((or (math-equal-int pow 3) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
459 (math-equal-int pow -3)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
460 (if (equal (nth 4 u) '((m . 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
461 (setq name (concat "Cubic-" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
462 (setq name (concat name "-cubed")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
463 (t |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
464 (setq name (concat name "^" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
465 (math-format-number (math-abs pow)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
466 (if (math-posp pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
467 (setq num-units (if num-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
468 (concat num-units " " name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
469 name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
470 (setq den-units (if den-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
471 (concat den-units " " name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
472 name)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
473 (cond ((eq (car-safe expr) '*) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
474 (calc-explain-units-rec (nth 1 expr) pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
475 (calc-explain-units-rec (nth 2 expr) pow)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
476 ((eq (car-safe expr) '/) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
477 (calc-explain-units-rec (nth 1 expr) pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
478 (calc-explain-units-rec (nth 2 expr) (- pow))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
479 ((memq (car-safe expr) '(neg + -)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
480 (calc-explain-units-rec (nth 1 expr) pow)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
481 ((and (eq (car-safe expr) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
482 (math-realp (nth 2 expr))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
483 (calc-explain-units-rec (nth 1 expr) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
484 (math-mul pow (nth 2 expr)))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
485 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
486 (defun calc-simplify-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
487 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
488 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
489 (calc-with-default-simplification |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
490 (calc-enter-result 1 "smun" (math-simplify-units (calc-top-n 1)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
491 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
492 (defun calc-view-units-table (n) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
493 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
494 (and n (setq math-units-table-buffer-valid nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
495 (let ((win (get-buffer-window "*Units Table*"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
496 (if (and win |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
497 math-units-table |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
498 math-units-table-buffer-valid) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
499 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
500 (bury-buffer (window-buffer win)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
501 (let ((curwin (selected-window))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
502 (select-window win) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
503 (switch-to-buffer nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
504 (select-window curwin))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
505 (math-build-units-table-buffer nil)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
506 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
507 (defun calc-enter-units-table (n) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
508 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
509 (and n (setq math-units-table-buffer-valid nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
510 (math-build-units-table-buffer t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
511 (message (substitute-command-keys "Type \\[calc] to return to the Calculator"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
512 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
513 (defun calc-define-unit (uname desc) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
514 (interactive "SDefine unit name: \nsDescription: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
515 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
516 (let ((form (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
517 (unit (assq uname math-additional-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
518 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
519 (setq math-additional-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
520 (cons (setq unit (list uname nil nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
521 math-additional-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
522 math-units-table nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
523 (setcar (cdr unit) (and (not (and (eq (car-safe form) 'var) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
524 (eq (nth 1 form) uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
525 (not (math-equal-int form 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
526 (math-format-flat-expr form 0))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
527 (setcar (cdr (cdr unit)) (and (not (equal desc "")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
528 desc)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
529 (calc-invalidate-units-table)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
530 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
531 (defun calc-undefine-unit (uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
532 (interactive "SUndefine unit name: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
533 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
534 (let ((unit (assq uname math-additional-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
535 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
536 (if (assq uname math-standard-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
537 (error "\"%s\" is a predefined unit name" uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
538 (error "Unit name \"%s\" not found" uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
539 (setq math-additional-units (delq unit math-additional-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
540 math-units-table nil))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
541 (calc-invalidate-units-table)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
542 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
543 (defun calc-invalidate-units-table () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
544 (setq math-units-table nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
545 (let ((buf (get-buffer "*Units Table*"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
546 (and buf |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
547 (save-excursion |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
548 (set-buffer buf) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
549 (save-excursion |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
550 (goto-char (point-min)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
551 (if (looking-at "Calculator Units Table") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
552 (let ((buffer-read-only nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
553 (insert "(Obsolete) ")))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
554 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
555 (defun calc-get-unit-definition (uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
556 (interactive "SGet definition for unit: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
557 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
558 (math-build-units-table) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
559 (let ((unit (assq uname math-units-table))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
560 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
561 (error "Unit name \"%s\" not found" uname)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
562 (let ((msg (nth 2 unit))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
563 (if (stringp msg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
564 (if (string-match "^\\*" msg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
565 (setq msg (substring msg 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
566 (setq msg (symbol-name uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
567 (if (nth 1 unit) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
568 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
569 (calc-enter-result 0 "ugdf" (nth 1 unit)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
570 (message "Derived unit: %s" msg)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
571 (calc-enter-result 0 "ugdf" (list 'var uname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
572 (intern |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
573 (concat "var-" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
574 (symbol-name uname))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
575 (message "Base unit: %s" msg)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
576 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
577 (defun calc-permanent-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
578 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
579 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
580 (let (pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
581 (set-buffer (find-file-noselect (substitute-in-file-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
582 calc-settings-file))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
583 (goto-char (point-min)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
584 (if (and (search-forward ";;; Custom units stored by Calc" nil t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
585 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
586 (beginning-of-line) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
587 (setq pos (point)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
588 (search-forward "\n;;; End of custom units" nil t))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
589 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
590 (beginning-of-line) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
591 (forward-line 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
592 (delete-region pos (point))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
593 (goto-char (point-max)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
594 (insert "\n\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
595 (forward-char -1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
596 (insert ";;; Custom units stored by Calc on " (current-time-string) "\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
597 (if math-additional-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
598 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
599 (insert "(setq math-additional-units '(\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
600 (let ((list math-additional-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
601 (while list |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
602 (insert " (" (symbol-name (car (car list))) " " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
603 (if (nth 1 (car list)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
604 (if (stringp (nth 1 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
605 (prin1-to-string (nth 1 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
606 (prin1-to-string (math-format-flat-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
607 (nth 1 (car list)) 0))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
608 "nil") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
609 " " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
610 (prin1-to-string (nth 2 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
611 ")\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
612 (setq list (cdr list)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
613 (insert "))\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
614 (insert ";;; (no custom units defined)\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
615 (insert ";;; End of custom units\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
616 (save-buffer)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
617 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
618 |
40785 | 619 |
620 (defun math-build-units-table () | |
621 (or math-units-table | |
622 (let* ((combined-units (append math-additional-units | |
623 math-standard-units)) | |
624 (unit-list (mapcar 'car combined-units)) | |
625 tab) | |
626 (message "Building units table...") | |
627 (setq math-units-table-buffer-valid nil) | |
628 (setq tab (mapcar (function | |
629 (lambda (x) | |
630 (list (car x) | |
631 (and (nth 1 x) | |
632 (if (stringp (nth 1 x)) | |
633 (let ((exp (math-read-plain-expr | |
634 (nth 1 x)))) | |
635 (if (eq (car-safe exp) 'error) | |
636 (error "Format error in definition of %s in units table: %s" | |
637 (car x) (nth 2 exp)) | |
638 exp)) | |
639 (nth 1 x))) | |
640 (nth 2 x) | |
641 (nth 3 x) | |
642 (and (not (nth 1 x)) | |
643 (list (cons (car x) 1)))))) | |
644 combined-units)) | |
645 (let ((math-units-table tab)) | |
646 (mapcar 'math-find-base-units tab)) | |
647 (message "Building units table...done") | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
648 (setq math-units-table tab)))) |
40785 | 649 |
650 (defun math-find-base-units (entry) | |
651 (if (eq (nth 4 entry) 'boom) | |
652 (error "Circular definition involving unit %s" (car entry))) | |
653 (or (nth 4 entry) | |
654 (let (base) | |
655 (setcar (nthcdr 4 entry) 'boom) | |
656 (math-find-base-units-rec (nth 1 entry) 1) | |
657 '(or base | |
658 (error "Dimensionless definition for unit %s" (car entry))) | |
659 (while (eq (cdr (car base)) 0) | |
660 (setq base (cdr base))) | |
661 (let ((b base)) | |
662 (while (cdr b) | |
663 (if (eq (cdr (car (cdr b))) 0) | |
664 (setcdr b (cdr (cdr b))) | |
665 (setq b (cdr b))))) | |
666 (setq base (sort base 'math-compare-unit-names)) | |
667 (setcar (nthcdr 4 entry) base) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
668 base))) |
40785 | 669 |
670 (defun math-compare-unit-names (a b) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
671 (memq (car b) (cdr (memq (car a) unit-list)))) |
40785 | 672 |
673 (defun math-find-base-units-rec (expr pow) | |
674 (let ((u (math-check-unit-name expr))) | |
675 (cond (u | |
676 (let ((ulist (math-find-base-units u))) | |
677 (while ulist | |
678 (let ((p (* (cdr (car ulist)) pow)) | |
679 (old (assq (car (car ulist)) base))) | |
680 (if old | |
681 (setcdr old (+ (cdr old) p)) | |
682 (setq base (cons (cons (car (car ulist)) p) base)))) | |
683 (setq ulist (cdr ulist))))) | |
684 ((math-scalarp expr)) | |
685 ((and (eq (car expr) '^) | |
686 (integerp (nth 2 expr))) | |
687 (math-find-base-units-rec (nth 1 expr) (* pow (nth 2 expr)))) | |
688 ((eq (car expr) '*) | |
689 (math-find-base-units-rec (nth 1 expr) pow) | |
690 (math-find-base-units-rec (nth 2 expr) pow)) | |
691 ((eq (car expr) '/) | |
692 (math-find-base-units-rec (nth 1 expr) pow) | |
693 (math-find-base-units-rec (nth 2 expr) (- pow))) | |
694 ((eq (car expr) 'neg) | |
695 (math-find-base-units-rec (nth 1 expr) pow)) | |
696 ((eq (car expr) '+) | |
697 (math-find-base-units-rec (nth 1 expr) pow)) | |
698 ((eq (car expr) 'var) | |
699 (or (eq (nth 1 expr) 'pi) | |
700 (error "Unknown name %s in defining expression for unit %s" | |
701 (nth 1 expr) (car entry)))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
702 (t (error "Malformed defining expression for unit %s" (car entry)))))) |
40785 | 703 |
704 | |
705 (defun math-units-in-expr-p (expr sub-exprs) | |
706 (and (consp expr) | |
707 (if (eq (car expr) 'var) | |
708 (math-check-unit-name expr) | |
709 (and (or sub-exprs | |
710 (memq (car expr) '(* / ^))) | |
711 (or (math-units-in-expr-p (nth 1 expr) sub-exprs) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
712 (math-units-in-expr-p (nth 2 expr) sub-exprs)))))) |
40785 | 713 |
714 (defun math-only-units-in-expr-p (expr) | |
715 (and (consp expr) | |
716 (if (eq (car expr) 'var) | |
717 (math-check-unit-name expr) | |
718 (if (memq (car expr) '(* /)) | |
719 (and (math-only-units-in-expr-p (nth 1 expr)) | |
720 (math-only-units-in-expr-p (nth 2 expr))) | |
721 (and (eq (car expr) '^) | |
722 (and (math-only-units-in-expr-p (nth 1 expr)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
723 (math-realp (nth 2 expr)))))))) |
40785 | 724 |
725 (defun math-single-units-in-expr-p (expr) | |
726 (cond ((math-scalarp expr) nil) | |
727 ((eq (car expr) 'var) | |
728 (math-check-unit-name expr)) | |
729 ((eq (car expr) '*) | |
730 (let ((u1 (math-single-units-in-expr-p (nth 1 expr))) | |
731 (u2 (math-single-units-in-expr-p (nth 2 expr)))) | |
732 (or (and u1 u2 'wrong) | |
733 u1 | |
734 u2))) | |
735 ((eq (car expr) '/) | |
736 (if (math-units-in-expr-p (nth 2 expr) nil) | |
737 'wrong | |
738 (math-single-units-in-expr-p (nth 1 expr)))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
739 (t 'wrong))) |
40785 | 740 |
741 (defun math-check-unit-name (v) | |
742 (and (eq (car-safe v) 'var) | |
743 (or (assq (nth 1 v) (or math-units-table (math-build-units-table))) | |
744 (let ((name (symbol-name (nth 1 v)))) | |
745 (and (> (length name) 1) | |
746 (assq (aref name 0) math-unit-prefixes) | |
747 (or (assq (intern (substring name 1)) math-units-table) | |
748 (and (eq (aref name 0) ?M) | |
749 (> (length name) 3) | |
750 (eq (aref name 1) ?e) | |
751 (eq (aref name 2) ?g) | |
752 (assq (intern (substring name 3)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
753 math-units-table)))))))) |
40785 | 754 |
755 | |
756 (defun math-to-standard-units (expr which-standard) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
757 (math-to-standard-rec expr)) |
40785 | 758 |
759 (defun math-to-standard-rec (expr) | |
760 (if (eq (car-safe expr) 'var) | |
761 (let ((u (math-check-unit-name expr)) | |
762 (base (nth 1 expr))) | |
763 (if u | |
764 (progn | |
765 (if (nth 1 u) | |
766 (setq expr (math-to-standard-rec (nth 1 u))) | |
767 (let ((st (assq (car u) which-standard))) | |
768 (if st | |
769 (setq expr (nth 1 st)) | |
770 (setq expr (list 'var (car u) | |
771 (intern (concat "var-" | |
772 (symbol-name | |
773 (car u))))))))) | |
774 (or (null u) | |
775 (eq base (car u)) | |
776 (setq expr (list '* | |
777 (nth 1 (assq (aref (symbol-name base) 0) | |
778 math-unit-prefixes)) | |
779 expr))) | |
780 expr) | |
781 (if (eq base 'pi) | |
782 (math-pi) | |
783 expr))) | |
784 (if (Math-primp expr) | |
785 expr | |
786 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
787 (mapcar 'math-to-standard-rec (cdr expr)))))) |
40785 | 788 |
789 (defun math-apply-units (expr units ulist &optional pure) | |
790 (if ulist | |
791 (let ((new 0) | |
792 value) | |
793 (setq expr (math-simplify-units expr)) | |
794 (or (math-numberp expr) | |
795 (error "Incompatible units")) | |
796 (while (cdr ulist) | |
797 (setq value (math-div expr (nth 1 (car ulist))) | |
798 value (math-floor (let ((calc-internal-prec | |
799 (1- calc-internal-prec))) | |
800 (math-normalize value))) | |
801 new (math-add new (math-mul value (car (car ulist)))) | |
802 expr (math-sub expr (math-mul value (nth 1 (car ulist)))) | |
803 ulist (cdr ulist))) | |
804 (math-add new (math-mul (math-div expr (nth 1 (car ulist))) | |
805 (car (car ulist))))) | |
806 (math-simplify-units (if pure | |
807 expr | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
808 (list '* expr units))))) |
40785 | 809 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
810 (defvar math-decompose-units-cache nil) |
40785 | 811 (defun math-decompose-units (units) |
812 (let ((u (math-check-unit-name units))) | |
813 (and u (eq (car-safe (nth 1 u)) '+) | |
814 (setq units (nth 1 u)))) | |
815 (setq units (calcFunc-expand units)) | |
816 (and (eq (car-safe units) '+) | |
817 (let ((entry (list units calc-internal-prec calc-prefer-frac))) | |
818 (or (equal entry (car math-decompose-units-cache)) | |
819 (let ((ulist nil) | |
820 (utemp units) | |
821 qty unit) | |
822 (while (eq (car-safe utemp) '+) | |
823 (setq ulist (cons (math-decompose-unit-part (nth 2 utemp)) | |
824 ulist) | |
825 utemp (nth 1 utemp))) | |
826 (setq ulist (cons (math-decompose-unit-part utemp) ulist) | |
827 utemp ulist) | |
828 (while (setq utemp (cdr utemp)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
829 (unless (equal (nth 2 (car utemp)) (nth 2 (car ulist))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
830 (error "Inconsistent units in sum"))) |
40785 | 831 (setq math-decompose-units-cache |
832 (cons entry | |
833 (sort ulist | |
834 (function | |
835 (lambda (x y) | |
836 (not (Math-lessp (nth 1 x) | |
837 (nth 1 y)))))))))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
838 (cdr math-decompose-units-cache)))) |
40785 | 839 |
840 (defun math-decompose-unit-part (unit) | |
841 (cons unit | |
842 (math-is-multiple (math-simplify-units (math-to-standard-units | |
843 unit nil)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
844 t))) |
40785 | 845 |
846 (defun math-find-compatible-unit (expr unit) | |
847 (let ((u (math-check-unit-name unit))) | |
848 (if u | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
849 (math-find-compatible-unit-rec expr 1)))) |
40785 | 850 |
851 (defun math-find-compatible-unit-rec (expr pow) | |
852 (cond ((eq (car-safe expr) '*) | |
853 (or (math-find-compatible-unit-rec (nth 1 expr) pow) | |
854 (math-find-compatible-unit-rec (nth 2 expr) pow))) | |
855 ((eq (car-safe expr) '/) | |
856 (or (math-find-compatible-unit-rec (nth 1 expr) pow) | |
857 (math-find-compatible-unit-rec (nth 2 expr) (- pow)))) | |
858 ((and (eq (car-safe expr) '^) | |
859 (integerp (nth 2 expr))) | |
860 (math-find-compatible-unit-rec (nth 1 expr) (* pow (nth 2 expr)))) | |
861 (t | |
862 (let ((u2 (math-check-unit-name expr))) | |
863 (if (equal (nth 4 u) (nth 4 u2)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
864 (cons expr pow)))))) |
40785 | 865 |
866 (defun math-convert-units (expr new-units &optional pure) | |
867 (math-with-extra-prec 2 | |
868 (let ((compat (and (not pure) (math-find-compatible-unit expr new-units))) | |
869 (unit-list nil) | |
870 (math-combining-units nil)) | |
871 (if compat | |
872 (math-simplify-units | |
873 (math-mul (math-mul (math-simplify-units | |
874 (math-div expr (math-pow (car compat) | |
875 (cdr compat)))) | |
876 (math-pow new-units (cdr compat))) | |
877 (math-simplify-units | |
878 (math-to-standard-units | |
879 (math-pow (math-div (car compat) new-units) | |
880 (cdr compat)) | |
881 nil)))) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
882 (when (setq unit-list (math-decompose-units new-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
883 (setq new-units (nth 2 (car unit-list)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
884 (when (eq (car-safe expr) '+) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
885 (setq expr (math-simplify-units expr))) |
40785 | 886 (if (math-units-in-expr-p expr t) |
887 (math-convert-units-rec expr) | |
888 (math-apply-units (math-to-standard-units | |
889 (list '/ expr new-units) nil) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
890 new-units unit-list pure)))))) |
40785 | 891 |
892 (defun math-convert-units-rec (expr) | |
893 (if (math-units-in-expr-p expr nil) | |
894 (math-apply-units (math-to-standard-units (list '/ expr new-units) nil) | |
895 new-units unit-list pure) | |
896 (if (Math-primp expr) | |
897 expr | |
898 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
899 (mapcar 'math-convert-units-rec (cdr expr)))))) |
40785 | 900 |
901 (defun math-convert-temperature (expr old new &optional pure) | |
902 (let* ((units (math-single-units-in-expr-p expr)) | |
903 (uold (if old | |
904 (if (or (null units) | |
905 (equal (nth 1 old) (car units))) | |
906 (math-check-unit-name old) | |
907 (error "Inconsistent temperature units")) | |
908 units)) | |
909 (unew (math-check-unit-name new))) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
910 (unless (and (consp unew) (nth 3 unew)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
911 (error "Not a valid temperature unit")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
912 (unless (and (consp uold) (nth 3 uold)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
913 (error "Not a pure temperature expression")) |
40785 | 914 (let ((v (car uold))) |
915 (setq expr (list '/ expr (list 'var v | |
916 (intern (concat "var-" | |
917 (symbol-name v))))))) | |
918 (or (eq (nth 3 uold) (nth 3 unew)) | |
919 (cond ((eq (nth 3 uold) 'K) | |
920 (setq expr (list '- expr '(float 27315 -2))) | |
921 (if (eq (nth 3 unew) 'F) | |
922 (setq expr (list '+ (list '* expr '(frac 9 5)) 32)))) | |
923 ((eq (nth 3 uold) 'C) | |
924 (if (eq (nth 3 unew) 'F) | |
925 (setq expr (list '+ (list '* expr '(frac 9 5)) 32)) | |
926 (setq expr (list '+ expr '(float 27315 -2))))) | |
927 (t | |
928 (setq expr (list '* (list '- expr 32) '(frac 5 9))) | |
929 (if (eq (nth 3 unew) 'K) | |
930 (setq expr (list '+ expr '(float 27315 -2))))))) | |
931 (if pure | |
932 expr | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
933 (list '* expr new)))) |
40785 | 934 |
935 | |
936 | |
937 (defun math-simplify-units (a) | |
938 (let ((math-simplifying-units t) | |
939 (calc-matrix-mode 'scalar)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
940 (math-simplify a))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
941 (defalias 'calcFunc-usimplify 'math-simplify-units) |
40785 | 942 |
943 (math-defsimplify (+ -) | |
944 (and math-simplifying-units | |
945 (math-units-in-expr-p (nth 1 expr) nil) | |
946 (let* ((units (math-extract-units (nth 1 expr))) | |
947 (ratio (math-simplify (math-to-standard-units | |
948 (list '/ (nth 2 expr) units) nil)))) | |
949 (if (math-units-in-expr-p ratio nil) | |
950 (progn | |
951 (calc-record-why "*Inconsistent units" expr) | |
952 expr) | |
953 (list '* (math-add (math-remove-units (nth 1 expr)) | |
954 (if (eq (car expr) '-) (math-neg ratio) ratio)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
955 units))))) |
40785 | 956 |
957 (math-defsimplify * | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
958 (math-simplify-units-prod)) |
40785 | 959 |
960 (defun math-simplify-units-prod () | |
961 (and math-simplifying-units | |
962 calc-autorange-units | |
963 (Math-realp (nth 1 expr)) | |
964 (let* ((num (math-float (nth 1 expr))) | |
965 (xpon (calcFunc-xpon num)) | |
966 (unitp (cdr (cdr expr))) | |
967 (unit (car unitp)) | |
968 (pow (if (eq (car expr) '*) 1 -1)) | |
969 u) | |
970 (and (eq (car-safe unit) '*) | |
971 (setq unitp (cdr unit) | |
972 unit (car unitp))) | |
973 (and (eq (car-safe unit) '^) | |
974 (integerp (nth 2 unit)) | |
975 (setq pow (* pow (nth 2 unit)) | |
976 unitp (cdr unit) | |
977 unit (car unitp))) | |
978 (and (setq u (math-check-unit-name unit)) | |
979 (integerp xpon) | |
980 (or (< xpon 0) | |
981 (>= xpon (if (eq (car u) 'm) 1 3))) | |
982 (let* ((uxpon 0) | |
983 (pref (if (< pow 0) | |
984 (reverse math-unit-prefixes) | |
985 math-unit-prefixes)) | |
986 (p pref) | |
987 pxpon pname) | |
988 (or (eq (car u) (nth 1 unit)) | |
989 (setq uxpon (* pow | |
990 (nth 2 (nth 1 (assq | |
991 (aref (symbol-name | |
992 (nth 1 unit)) 0) | |
993 math-unit-prefixes)))))) | |
994 (setq xpon (+ xpon uxpon)) | |
995 (while (and p | |
996 (or (memq (car (car p)) '(?d ?D ?h ?H)) | |
997 (and (eq (car (car p)) ?c) | |
998 (not (eq (car u) 'm))) | |
999 (< xpon (setq pxpon (* (nth 2 (nth 1 (car p))) | |
1000 pow))) | |
1001 (progn | |
1002 (setq pname (math-build-var-name | |
1003 (if (eq (car (car p)) 0) | |
1004 (car u) | |
1005 (concat (char-to-string | |
1006 (car (car p))) | |
1007 (symbol-name | |
1008 (car u)))))) | |
1009 (and (/= (car (car p)) 0) | |
1010 (assq (nth 1 pname) | |
1011 math-units-table))))) | |
1012 (setq p (cdr p))) | |
1013 (and p | |
1014 (/= pxpon uxpon) | |
1015 (or (not (eq p pref)) | |
1016 (< xpon (+ pxpon (* (math-abs pow) 3)))) | |
1017 (progn | |
1018 (setcar (cdr expr) | |
1019 (let ((calc-prefer-frac nil)) | |
1020 (calcFunc-scf (nth 1 expr) | |
1021 (- uxpon pxpon)))) | |
1022 (setcar unitp pname) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1023 expr))))))) |
40785 | 1024 |
1025 (math-defsimplify / | |
1026 (and math-simplifying-units | |
1027 (let ((np (cdr expr)) | |
1028 (try-cancel-units 0) | |
1029 n nn) | |
1030 (setq n (if (eq (car-safe (nth 2 expr)) '*) | |
1031 (cdr (nth 2 expr)) | |
1032 (nthcdr 2 expr))) | |
1033 (if (math-realp (car n)) | |
1034 (progn | |
1035 (setcar (cdr expr) (math-mul (nth 1 expr) | |
1036 (let ((calc-prefer-frac nil)) | |
1037 (math-div 1 (car n))))) | |
1038 (setcar n 1))) | |
1039 (while (eq (car-safe (setq n (car np))) '*) | |
1040 (math-simplify-units-divisor (cdr n) (cdr (cdr expr))) | |
1041 (setq np (cdr (cdr n)))) | |
1042 (math-simplify-units-divisor np (cdr (cdr expr))) | |
1043 (if (eq try-cancel-units 0) | |
1044 (let* ((math-simplifying-units nil) | |
1045 (base (math-simplify (math-to-standard-units expr nil)))) | |
1046 (if (Math-numberp base) | |
1047 (setq expr base)))) | |
1048 (if (eq (car-safe expr) '/) | |
1049 (math-simplify-units-prod)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1050 expr))) |
40785 | 1051 |
1052 (defun math-simplify-units-divisor (np dp) | |
1053 (let ((n (car np)) | |
1054 d dd temp) | |
1055 (while (eq (car-safe (setq d (car dp))) '*) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1056 (when (setq temp (math-simplify-units-quotient n (nth 1 d))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1057 (setcar np (setq n temp)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1058 (setcar (cdr d) 1)) |
40785 | 1059 (setq dp (cdr (cdr d)))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1060 (when (setq temp (math-simplify-units-quotient n d)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1061 (setcar np (setq n temp)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1062 (setcar dp 1)))) |
40785 | 1063 |
1064 ;; Simplify, e.g., "in / cm" to "2.54" in a units expression. | |
1065 (defun math-simplify-units-quotient (n d) | |
1066 (let ((pow1 1) | |
1067 (pow2 1)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1068 (when (and (eq (car-safe n) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1069 (integerp (nth 2 n))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1070 (setq pow1 (nth 2 n) n (nth 1 n))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1071 (when (and (eq (car-safe d) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1072 (integerp (nth 2 d))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1073 (setq pow2 (nth 2 d) d (nth 1 d))) |
40785 | 1074 (let ((un (math-check-unit-name n)) |
1075 (ud (math-check-unit-name d))) | |
1076 (and un ud | |
1077 (if (and (equal (nth 4 un) (nth 4 ud)) | |
1078 (eq pow1 pow2)) | |
1079 (math-to-standard-units (list '/ n d) nil) | |
1080 (let (ud1) | |
1081 (setq un (nth 4 un) | |
1082 ud (nth 4 ud)) | |
1083 (while un | |
1084 (setq ud1 ud) | |
1085 (while ud1 | |
1086 (and (eq (car (car un)) (car (car ud1))) | |
1087 (setq try-cancel-units | |
1088 (+ try-cancel-units | |
1089 (- (* (cdr (car un)) pow1) | |
1090 (* (cdr (car ud)) pow2))))) | |
1091 (setq ud1 (cdr ud1))) | |
1092 (setq un (cdr un))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1093 nil)))))) |
40785 | 1094 |
1095 (math-defsimplify ^ | |
1096 (and math-simplifying-units | |
1097 (math-realp (nth 2 expr)) | |
1098 (if (memq (car-safe (nth 1 expr)) '(* /)) | |
1099 (list (car (nth 1 expr)) | |
1100 (list '^ (nth 1 (nth 1 expr)) (nth 2 expr)) | |
1101 (list '^ (nth 2 (nth 1 expr)) (nth 2 expr))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1102 (math-simplify-units-pow (nth 1 expr) (nth 2 expr))))) |
40785 | 1103 |
1104 (math-defsimplify calcFunc-sqrt | |
1105 (and math-simplifying-units | |
1106 (if (memq (car-safe (nth 1 expr)) '(* /)) | |
1107 (list (car (nth 1 expr)) | |
1108 (list 'calcFunc-sqrt (nth 1 (nth 1 expr))) | |
1109 (list 'calcFunc-sqrt (nth 2 (nth 1 expr)))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1110 (math-simplify-units-pow (nth 1 expr) '(frac 1 2))))) |
40785 | 1111 |
1112 (math-defsimplify (calcFunc-floor | |
1113 calcFunc-ceil | |
1114 calcFunc-round | |
1115 calcFunc-rounde | |
1116 calcFunc-roundu | |
1117 calcFunc-trunc | |
1118 calcFunc-float | |
1119 calcFunc-frac | |
1120 calcFunc-abs | |
1121 calcFunc-clean) | |
1122 (and math-simplifying-units | |
1123 (= (length expr) 2) | |
1124 (if (math-only-units-in-expr-p (nth 1 expr)) | |
1125 (nth 1 expr) | |
1126 (if (and (memq (car-safe (nth 1 expr)) '(* /)) | |
1127 (or (math-only-units-in-expr-p | |
1128 (nth 1 (nth 1 expr))) | |
1129 (math-only-units-in-expr-p | |
1130 (nth 2 (nth 1 expr))))) | |
1131 (list (car (nth 1 expr)) | |
1132 (cons (car expr) | |
1133 (cons (nth 1 (nth 1 expr)) | |
1134 (cdr (cdr expr)))) | |
1135 (cons (car expr) | |
1136 (cons (nth 2 (nth 1 expr)) | |
1137 (cdr (cdr expr))))))))) | |
1138 | |
1139 (defun math-simplify-units-pow (a pow) | |
1140 (if (and (eq (car-safe a) '^) | |
1141 (math-check-unit-name (nth 1 a)) | |
1142 (math-realp (nth 2 a))) | |
1143 (list '^ (nth 1 a) (math-mul pow (nth 2 a))) | |
1144 (let* ((u (math-check-unit-name a)) | |
1145 (pf (math-to-simple-fraction pow)) | |
1146 (d (and (eq (car-safe pf) 'frac) (nth 2 pf)))) | |
1147 (and u d | |
1148 (math-units-are-multiple u d) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1149 (list '^ (math-to-standard-units a nil) pow))))) |
40785 | 1150 |
1151 | |
1152 (defun math-units-are-multiple (u n) | |
1153 (setq u (nth 4 u)) | |
1154 (while (and u (= (% (cdr (car u)) n) 0)) | |
1155 (setq u (cdr u))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1156 (null u)) |
40785 | 1157 |
1158 (math-defsimplify calcFunc-sin | |
1159 (and math-simplifying-units | |
1160 (math-units-in-expr-p (nth 1 expr) nil) | |
1161 (let ((rad (math-simplify-units | |
1162 (math-evaluate-expr | |
1163 (math-to-standard-units (nth 1 expr) nil)))) | |
1164 (calc-angle-mode 'rad)) | |
1165 (and (eq (car-safe rad) '*) | |
1166 (math-realp (nth 1 rad)) | |
1167 (eq (car-safe (nth 2 rad)) 'var) | |
1168 (eq (nth 1 (nth 2 rad)) 'rad) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1169 (list 'calcFunc-sin (nth 1 rad)))))) |
40785 | 1170 |
1171 (math-defsimplify calcFunc-cos | |
1172 (and math-simplifying-units | |
1173 (math-units-in-expr-p (nth 1 expr) nil) | |
1174 (let ((rad (math-simplify-units | |
1175 (math-evaluate-expr | |
1176 (math-to-standard-units (nth 1 expr) nil)))) | |
1177 (calc-angle-mode 'rad)) | |
1178 (and (eq (car-safe rad) '*) | |
1179 (math-realp (nth 1 rad)) | |
1180 (eq (car-safe (nth 2 rad)) 'var) | |
1181 (eq (nth 1 (nth 2 rad)) 'rad) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1182 (list 'calcFunc-cos (nth 1 rad)))))) |
40785 | 1183 |
1184 (math-defsimplify calcFunc-tan | |
1185 (and math-simplifying-units | |
1186 (math-units-in-expr-p (nth 1 expr) nil) | |
1187 (let ((rad (math-simplify-units | |
1188 (math-evaluate-expr | |
1189 (math-to-standard-units (nth 1 expr) nil)))) | |
1190 (calc-angle-mode 'rad)) | |
1191 (and (eq (car-safe rad) '*) | |
1192 (math-realp (nth 1 rad)) | |
1193 (eq (car-safe (nth 2 rad)) 'var) | |
1194 (eq (nth 1 (nth 2 rad)) 'rad) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1195 (list 'calcFunc-tan (nth 1 rad)))))) |
40785 | 1196 |
1197 | |
1198 (defun math-remove-units (expr) | |
1199 (if (math-check-unit-name expr) | |
1200 1 | |
1201 (if (Math-primp expr) | |
1202 expr | |
1203 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1204 (mapcar 'math-remove-units (cdr expr)))))) |
40785 | 1205 |
1206 (defun math-extract-units (expr) | |
1207 (if (memq (car-safe expr) '(* /)) | |
1208 (cons (car expr) | |
1209 (mapcar 'math-extract-units (cdr expr))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1210 (if (math-check-unit-name expr) expr 1))) |
40785 | 1211 |
1212 (defun math-build-units-table-buffer (enter-buffer) | |
1213 (if (not (and math-units-table math-units-table-buffer-valid | |
1214 (get-buffer "*Units Table*"))) | |
1215 (let ((buf (get-buffer-create "*Units Table*")) | |
1216 (uptr (math-build-units-table)) | |
1217 (calc-language (if (eq calc-language 'big) nil calc-language)) | |
1218 (calc-float-format '(float 0)) | |
1219 (calc-group-digits nil) | |
1220 (calc-number-radix 10) | |
1221 (calc-point-char ".") | |
1222 (std nil) | |
1223 u name shadowed) | |
1224 (save-excursion | |
1225 (message "Formatting units table...") | |
1226 (set-buffer buf) | |
1227 (setq buffer-read-only nil) | |
1228 (erase-buffer) | |
1229 (insert "Calculator Units Table:\n\n") | |
1230 (insert "Unit Type Definition Description\n\n") | |
1231 (while uptr | |
1232 (setq u (car uptr) | |
1233 name (nth 2 u)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1234 (when (eq (car u) 'm) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1235 (setq std t)) |
40785 | 1236 (setq shadowed (and std (assq (car u) math-additional-units))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1237 (when (and name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1238 (> (length name) 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1239 (eq (aref name 0) ?\*)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1240 (unless (eq uptr math-units-table) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1241 (insert "\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1242 (setq name (substring name 1))) |
40785 | 1243 (insert " ") |
1244 (and shadowed (insert "(")) | |
1245 (insert (symbol-name (car u))) | |
1246 (and shadowed (insert ")")) | |
1247 (if (nth 3 u) | |
1248 (progn | |
1249 (indent-to 10) | |
1250 (insert (symbol-name (nth 3 u)))) | |
1251 (or std | |
1252 (progn | |
1253 (indent-to 10) | |
1254 (insert "U")))) | |
1255 (indent-to 14) | |
1256 (and shadowed (insert "(")) | |
1257 (if (nth 1 u) | |
1258 (insert (math-format-value (nth 1 u) 80)) | |
1259 (insert (symbol-name (car u)))) | |
1260 (and shadowed (insert ")")) | |
1261 (indent-to 41) | |
1262 (insert " ") | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1263 (when name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1264 (insert name)) |
40785 | 1265 (if shadowed |
1266 (insert " (redefined above)") | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1267 (unless (nth 1 u) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1268 (insert " (base unit)"))) |
40785 | 1269 (insert "\n") |
1270 (setq uptr (cdr uptr))) | |
1271 (insert "\n\nUnit Prefix Table:\n\n") | |
1272 (setq uptr math-unit-prefixes) | |
1273 (while uptr | |
1274 (setq u (car uptr)) | |
1275 (insert " " (char-to-string (car u))) | |
1276 (if (equal (nth 1 u) (nth 1 (nth 1 uptr))) | |
1277 (insert " " (char-to-string (car (car (setq uptr (cdr uptr))))) | |
1278 " ") | |
1279 (insert " ")) | |
1280 (insert "10^" (int-to-string (nth 2 (nth 1 u)))) | |
1281 (indent-to 15) | |
1282 (insert " " (nth 2 u) "\n") | |
1283 (while (eq (car (car (setq uptr (cdr uptr)))) 0))) | |
1284 (insert "\n") | |
1285 (setq buffer-read-only t) | |
1286 (message "Formatting units table...done")) | |
1287 (setq math-units-table-buffer-valid t) | |
1288 (let ((oldbuf (current-buffer))) | |
1289 (set-buffer buf) | |
1290 (goto-char (point-min)) | |
1291 (set-buffer oldbuf)) | |
1292 (if enter-buffer | |
1293 (pop-to-buffer buf) | |
1294 (display-buffer buf))) | |
1295 (if enter-buffer | |
1296 (pop-to-buffer (get-buffer "*Units Table*")) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1297 (display-buffer (get-buffer "*Units Table*"))))) |
40785 | 1298 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1299 ;; Local Variables: |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1300 ;; coding: iso-latin-1 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1301 ;; End: |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1302 |
52401 | 1303 ;;; arch-tag: e993314f-3adc-4191-be61-4ef8874881c4 |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1304 ;;; calc-units.el ends here |