aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/calc/calc-units.el139
1 files changed, 92 insertions, 47 deletions
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index 8ba6465e902..4ab65877cf4 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -48,14 +48,17 @@
48(defvar math-standard-units 48(defvar math-standard-units
49 '( ;; Length 49 '( ;; Length
50 ( m nil "*Meter" ) 50 ( m nil "*Meter" )
51 ( in "254*10^(-2) cm" "Inch" ) 51 ( in "254*10^(-2) cm" "Inch" nil
52 ( ft "12 in" "Foot" ) 52 "2.54 cm")
53 ( ft "12 in" "Foot")
53 ( yd "3 ft" "Yard" ) 54 ( yd "3 ft" "Yard" )
54 ( mi "5280 ft" "Mile" ) 55 ( mi "5280 ft" "Mile" )
55 ( au "149597870691. m" "Astronomical Unit" ) 56 ( au "149597870691. m" "Astronomical Unit" nil
57 "149597870691 m (*)")
56 ;; (approx) NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html) 58 ;; (approx) NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html)
57 ( lyr "c yr" "Light Year" ) 59 ( lyr "c yr" "Light Year" )
58 ( pc "3.0856775854e16 m" "Parsec" ) ;; (approx) ESUWM 60 ( pc "3.0856775854e16 m" "Parsec" nil
61 "3.0856775854e16 m (*)") ;; (approx) ESUWM
59 ( nmi "1852 m" "Nautical Mile" ) 62 ( nmi "1852 m" "Nautical Mile" )
60 ( fath "6 ft" "Fathom" ) 63 ( fath "6 ft" "Fathom" )
61 ( mu "1 um" "Micron" ) 64 ( mu "1 um" "Micron" )
@@ -89,10 +92,12 @@
89 ( tbsp "3 tsp" "Tablespoon" ) 92 ( tbsp "3 tsp" "Tablespoon" )
90 ;; ESUWM defines a US gallon as 231 in^3. 93 ;; ESUWM defines a US gallon as 231 in^3.
91 ;; That gives the following exact value for tsp. 94 ;; That gives the following exact value for tsp.
92 ( tsp "492892159375*10^(-11) ml" "Teaspoon" ) 95 ( tsp "492892159375*10^(-11) ml" "Teaspoon" nil
96 "4.92892159375 ml")
93 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" ) 97 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" )
94 ( galC "galUK" "Canadian Gallon" ) 98 ( galC "galUK" "Canadian Gallon" )
95 ( galUK "454609*10^(-5) L" "UK Gallon" ) ;; NIST 99 ( galUK "454609*10^(-5) L" "UK Gallon" nil
100 "4.54609 L") ;; NIST
96 101
97 ;; Time 102 ;; Time
98 ( s nil "*Second" ) 103 ( s nil "*Second" )
@@ -112,20 +117,26 @@
112 ( c "299792458 m/s" "Speed of light" ) ;;; CODATA 117 ( c "299792458 m/s" "Speed of light" ) ;;; CODATA
113 118
114 ;; Acceleration 119 ;; Acceleration
115 ( ga "980665*10^(-5) m/s^2" "*\"g\" acceleration" ) ;; CODATA 120 ( ga "980665*10^(-5) m/s^2" "*\"g\" acceleration" nil
121 "9.80665 m / s^2") ;; CODATA
116 122
117 ;; Mass 123 ;; Mass
118 ( g nil "*Gram" ) 124 ( g nil "*Gram" )
119 ( lb "16 oz" "Pound (mass)" ) 125 ( lb "16 oz" "Pound (mass)" )
120 ( oz "28349523125*10^(-9) g" "Ounce (mass)" ) ;; ESUWM 126 ( oz "28349523125*10^(-9) g" "Ounce (mass)" nil
127 "28.349523125 g") ;; ESUWM
121 ( ton "2000 lb" "Ton" ) 128 ( ton "2000 lb" "Ton" )
122 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" ) 129 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
123 ( t "1000 kg" "Metric ton" ) 130 ( t "1000 kg" "Metric ton" )
124 ( tonUK "10160469088*10^(-7) kg" "UK ton" ) ;; ESUWM 131 ( tonUK "10160469088*10^(-7) kg" "UK ton" nil
132 "1016.0469088 kg") ;; ESUWM
125 ( lbt "12 ozt" "Troy pound" ) 133 ( lbt "12 ozt" "Troy pound" )
126 ( ozt "31.10347680 g" "Troy ounce" ) ;; (approx) ESUWM 134 ( ozt "31.10347680 g" "Troy ounce" nil
127 ( ct "(2/10) g" "Carat" ) ;; ESUWM 135 "31.10347680 g (*)") ;; (approx) ESUWM
128 ( u "1.660538782e-27 kg" "Unified atomic mass" );;(approx) CODATA 136 ( ct "(2/10) g" "Carat" nil
137 "0.2 g") ;; ESUWM
138 ( u "1.660538782e-27 kg" "Unified atomic mass" nil
139 "1.660538782e-27 kg (*)");;(approx) CODATA
129 140
130 ;; Force 141 ;; Force
131 ( N "m kg/s^2" "*Newton" ) 142 ( N "m kg/s^2" "*Newton" )
@@ -133,13 +144,16 @@
133 ( gf "ga g" "Gram (force)" ) 144 ( gf "ga g" "Gram (force)" )
134 ( lbf "ga lb" "Pound (force)" ) 145 ( lbf "ga lb" "Pound (force)" )
135 ( kip "1000 lbf" "Kilopound (force)" ) 146 ( kip "1000 lbf" "Kilopound (force)" )
136 ( pdl "138254954376*10^(-12) N" "Poundal" ) ;; ESUWM 147 ( pdl "138254954376*10^(-12) N" "Poundal" nil
148 "0.138254954376 N") ;; ESUWM
137 149
138 ;; Energy 150 ;; Energy
139 ( J "N m" "*Joule" ) 151 ( J "N m" "*Joule" )
140 ( erg "10^(-7) J" "Erg" ) 152 ( erg "10^(-7) J" "Erg" )
141 ( cal "4.18674 J" "International Table Calorie" );;(approx) ESUWM 153 ( cal "4.18674 J" "International Table Calorie" nil
142 ( Btu "105505585262*10^(-8) J" "International Table Btu" ) ;; ESUWM 154 "4.18674 J (*)");;(approx) ESUWM
155 ( Btu "105505585262*10^(-8) J" "International Table Btu" nil
156 "1055.05585262 J") ;; ESUWM
143 ( eV "ech V" "Electron volt" ) 157 ( eV "ech V" "Electron volt" )
144 ( ev "eV" "Electron volt" ) 158 ( ev "eV" "Electron volt" )
145 ( therm "105506000 J" "EEC therm" ) 159 ( therm "105506000 J" "EEC therm" )
@@ -153,7 +167,8 @@
153 167
154 ;; Power 168 ;; Power
155 ( W "J/s" "*Watt" ) 169 ( W "J/s" "*Watt" )
156 ( hp "745.699871581 W" "Horsepower" ) ;;(approx) ESUWM 170 ( hp "745.699871581 W" "Horsepower" nil
171 "745.699871581 W (*)") ;;(approx) ESUWM
157 172
158 ;; Temperature 173 ;; Temperature
159 ( K nil "*Degree Kelvin" K ) 174 ( K nil "*Degree Kelvin" K )
@@ -168,10 +183,13 @@
168 ( Pa "N/m^2" "*Pascal" ) 183 ( Pa "N/m^2" "*Pascal" )
169 ( bar "10^5 Pa" "Bar" ) 184 ( bar "10^5 Pa" "Bar" )
170 ( atm "101325 Pa" "Standard atmosphere" ) ;; CODATA 185 ( atm "101325 Pa" "Standard atmosphere" ) ;; CODATA
171 ( Torr "1.333224e2 Pa" "Torr" ) ;;(approx) NIST 186 ( Torr "1.333224e2 Pa" "Torr" nil
187 "1.333224e2 Pa (*)") ;;(approx) NIST
172 ( mHg "1000 Torr" "Meter of mercury" ) 188 ( mHg "1000 Torr" "Meter of mercury" )
173 ( inHg "254*10^(-1) mmHg" "Inch of mercury" ) 189 ( inHg "254*10^(-1) mmHg" "Inch of mercury" nil
174 ( inH2O "2.490889e2 Pa" "Inch of water" ) ;;(approx) NIST 190 "25.4 mmHg")
191 ( inH2O "2.490889e2 Pa" "Inch of water" nil
192 "2.490889e2 Pa (*)") ;;(approx) NIST
175 ( psi "lbf/in^2" "Pounds per square inch" ) 193 ( psi "lbf/in^2" "Pounds per square inch" )
176 194
177 ;; Viscosity 195 ;; Viscosity
@@ -183,7 +201,8 @@
183 ( C "A s" "Coulomb" ) 201 ( C "A s" "Coulomb" )
184 ( Fdy "ech Nav" "Faraday" ) 202 ( Fdy "ech Nav" "Faraday" )
185 ( e "ech" "Elementary charge" ) 203 ( e "ech" "Elementary charge" )
186 ( ech "1.602176487e-19 C" "Elementary charge" ) ;;(approx) CODATA 204 ( ech "1.602176487e-19 C" "Elementary charge" nil
205 "1.602176487e-19 C (*)") ;;(approx) CODATA
187 ( V "W/A" "Volt" ) 206 ( V "W/A" "Volt" )
188 ( ohm "V/A" "Ohm" ) 207 ( ohm "V/A" "Ohm" )
189 ( mho "A/V" "Mho" ) 208 ( mho "A/V" "Mho" )
@@ -200,9 +219,11 @@
200 ( lm "cd sr" "Lumen" ) 219 ( lm "cd sr" "Lumen" )
201 ( lx "lm/m^2" "Lux" ) 220 ( lx "lm/m^2" "Lux" )
202 ( ph "10000 lx" "Phot" ) 221 ( ph "10000 lx" "Phot" )
203 ( fc "10.76391 lx" "Footcandle" ) ;;(approx) NIST 222 ( fc "10.76391 lx" "Footcandle" nil
223 "10.76391 lx (*)") ;;(approx) NIST
204 ( lam "10000 lm/m^2" "Lambert" ) 224 ( lam "10000 lm/m^2" "Lambert" )
205 ( flam "3.426259 cd/m^2" "Footlambert" ) ;;(approx) NIST 225 ( flam "3.426259 cd/m^2" "Footlambert" nil
226 "3.426259 cd / m^2 (*)") ;;(approx) NIST
206 227
207 ;; Radioactivity 228 ;; Radioactivity
208 ( Bq "1/s" "*Becquerel" ) 229 ( Bq "1/s" "*Becquerel" )
@@ -231,24 +252,41 @@
231 252
232 ;; Other physical quantities 253 ;; Other physical quantities
233 ;; The values are from CODATA, and are approximate. 254 ;; The values are from CODATA, and are approximate.
234 ( h "6.62606896e-34 J s" "*Planck's constant" ) 255 ( h "6.62606896e-34 J s" "*Planck's constant" nil
256 "6.62606896e-34 J s (*)")
235 ( hbar "h / (2 pi)" "Planck's constant" ) 257 ( hbar "h / (2 pi)" "Planck's constant" )
236 ( mu0 "4 pi 10^(-7) H/m" "Permeability of vacuum" ) 258 ( mu0 "4 pi 10^(-7) H/m" "Permeability of vacuum" nil
237 ( G "6.67428e-11 m^3/(kg s^2)" "Gravitational constant" ) 259 "4 pi 10^(-7) H/m (*)")
238 ( Nav "6.02214179e23 / mol" "Avagadro's constant" ) 260 ( G "6.67428e-11 m^3/(kg s^2)" "Gravitational constant" nil
239 ( me "9.10938215e-31 kg" "Electron rest mass" ) 261 "6.67428e-11 m^3/(kg s^2) (*)")
240 ( mp "1.672621637e-27 kg" "Proton rest mass" ) 262 ( Nav "6.02214179e23 / mol" "Avagadro's constant" nil
241 ( mn "1.674927211e-27 kg" "Neutron rest mass" ) 263 "6.02214179e23 / mol (*)")
242 ( mmu "1.88353130e-28 kg" "Muon rest mass" ) 264 ( me "9.10938215e-31 kg" "Electron rest mass" nil
243 ( Ryd "10973731.568527 /m" "Rydberg's constant" ) 265 "9.10938215e-31 kg (*)")
244 ( k "1.3806504e-23 J/K" "Boltzmann's constant" ) 266 ( mp "1.672621637e-27 kg" "Proton rest mass" nil
245 ( alpha "7.2973525376e-3" "Fine structure constant" ) 267 "1.672621637e-27 kg (*)")
246 ( muB "927.400915e-26 J/T" "Bohr magneton" ) 268 ( mn "1.674927211e-27 kg" "Neutron rest mass" nil
247 ( muN "5.05078324e-27 J/T" "Nuclear magneton" ) 269 "1.674927211e-27 kg (*)")
248 ( mue "-928.476377e-26 J/T" "Electron magnetic moment" ) 270 ( mmu "1.88353130e-28 kg" "Muon rest mass" nil
249 ( mup "1.410606662e-26 J/T" "Proton magnetic moment" ) 271 "1.88353130e-28 kg (*)")
250 ( R0 "8.314472 J/(mol K)" "Molar gas constant" ) 272 ( Ryd "10973731.568527 /m" "Rydberg's constant" nil
251 ( V0 "22.710981e-3 m^3/mol" "Standard volume of ideal gas" ))) 273 "10973731.568527 /m (*)")
274 ( k "1.3806504e-23 J/K" "Boltzmann's constant" nil
275 "1.3806504e-23 J/K (*)")
276 ( alpha "7.2973525376e-3" "Fine structure constant" nil
277 "7.2973525376e-3 (*)")
278 ( muB "927.400915e-26 J/T" "Bohr magneton" nil
279 "927.400915e-26 J/T (*)")
280 ( muN "5.05078324e-27 J/T" "Nuclear magneton" nil
281 "5.05078324e-27 J/T (*)")
282 ( mue "-928.476377e-26 J/T" "Electron magnetic moment" nil
283 "-928.476377e-26 J/T (*)")
284 ( mup "1.410606662e-26 J/T" "Proton magnetic moment" nil
285 "1.410606662e-26 J/T (*)")
286 ( R0 "8.314472 J/(mol K)" "Molar gas constant" nil
287 "8.314472 J/(mol K) (*)")
288 ( V0 "22.710981e-3 m^3/mol" "Standard volume of ideal gas" nil
289 "22.710981e-3 m^3/mol (*)")))
252 290
253 291
254(defvar math-additional-units nil 292(defvar math-additional-units nil
@@ -616,14 +654,15 @@ If EXPR is nil, return nil."
616 (math-build-units-table-buffer t) 654 (math-build-units-table-buffer t)
617 (message "%s" (substitute-command-keys "Type \\[calc] to return to the Calculator"))) 655 (message "%s" (substitute-command-keys "Type \\[calc] to return to the Calculator")))
618 656
619(defun calc-define-unit (uname desc) 657(defun calc-define-unit (uname desc &optional disp)
620 (interactive "SDefine unit name: \nsDescription: ") 658 (interactive "SDefine unit name: \nsDescription: \nP")
659 (if disp (setq disp (read-string "Display definition: ")))
621 (calc-wrapper 660 (calc-wrapper
622 (let ((form (calc-top-n 1)) 661 (let ((form (calc-top-n 1))
623 (unit (assq uname math-additional-units))) 662 (unit (assq uname math-additional-units)))
624 (or unit 663 (or unit
625 (setq math-additional-units 664 (setq math-additional-units
626 (cons (setq unit (list uname nil nil)) 665 (cons (setq unit (list uname nil nil nil nil))
627 math-additional-units) 666 math-additional-units)
628 math-units-table nil)) 667 math-units-table nil))
629 (setcar (cdr unit) (and (not (and (eq (car-safe form) 'var) 668 (setcar (cdr unit) (and (not (and (eq (car-safe form) 'var)
@@ -631,7 +670,9 @@ If EXPR is nil, return nil."
631 (not (math-equal-int form 1)) 670 (not (math-equal-int form 1))
632 (math-format-flat-expr form 0))) 671 (math-format-flat-expr form 0)))
633 (setcar (cdr (cdr unit)) (and (not (equal desc "")) 672 (setcar (cdr (cdr unit)) (and (not (equal desc ""))
634 desc)))) 673 desc))
674 (if disp
675 (setcar (cdr (cdr (cdr (cdr unit)))) disp))))
635 (calc-invalidate-units-table)) 676 (calc-invalidate-units-table))
636 677
637(defun calc-undefine-unit (uname) 678(defun calc-undefine-unit (uname)
@@ -752,7 +793,8 @@ If EXPR is nil, return nil."
752 (nth 2 x) 793 (nth 2 x)
753 (nth 3 x) 794 (nth 3 x)
754 (and (not (nth 1 x)) 795 (and (not (nth 1 x))
755 (list (cons (car x) 1)))))) 796 (list (cons (car x) 1)))
797 (nth 4 x))))
756 combined-units)) 798 combined-units))
757 (let ((math-units-table tab)) 799 (let ((math-units-table tab))
758 (mapc 'math-find-base-units tab)) 800 (mapc 'math-find-base-units tab))
@@ -1420,6 +1462,7 @@ If EXPR is nil, return nil."
1420 (let ((inhibit-read-only t)) 1462 (let ((inhibit-read-only t))
1421 (erase-buffer) 1463 (erase-buffer)
1422 (insert "Calculator Units Table:\n\n") 1464 (insert "Calculator Units Table:\n\n")
1465 (insert "(All definitions are exact unless marked with an (*).)\n\n")
1423 (insert "Unit Type Definition Description\n\n") 1466 (insert "Unit Type Definition Description\n\n")
1424 (while uptr 1467 (while uptr
1425 (setq u (car uptr) 1468 (setq u (car uptr)
@@ -1447,9 +1490,11 @@ If EXPR is nil, return nil."
1447 (insert "U")))) 1490 (insert "U"))))
1448 (indent-to 14) 1491 (indent-to 14)
1449 (and shadowed (insert "(")) 1492 (and shadowed (insert "("))
1450 (if (nth 1 u) 1493 (if (nth 5 u)
1451 (insert (math-format-value (nth 1 u) 80)) 1494 (insert (nth 5 u))
1452 (insert (symbol-name (car u)))) 1495 (if (nth 1 u)
1496 (insert (math-format-value (nth 1 u) 80))
1497 (insert (symbol-name (car u)))))
1453 (and shadowed (insert ")")) 1498 (and shadowed (insert ")"))
1454 (indent-to 41) 1499 (indent-to 41)
1455 (insert " ") 1500 (insert " ")