aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters2001-11-19 07:42:20 +0000
committerColin Walters2001-11-19 07:42:20 +0000
commit8cd8ee52f71a343201db7d225e2b6c6036695a3a (patch)
tree1e9618162dd465c27f7952a1ee4fe1d728544bb0
parentcb196072886f3310b370d7da6b75d9d096058348 (diff)
downloademacs-8cd8ee52f71a343201db7d225e2b6c6036695a3a.tar.gz
emacs-8cd8ee52f71a343201db7d225e2b6c6036695a3a.zip
(calcFunc-usimplify): Add missing quote to defalias argument.
Change all toplevel `setq' forms to `defvar' forms, and move them before their first use. Use `when', `unless'. Remove trailing periods from error forms. Add description and headers suggested by Emacs Lisp coding conventions.
-rw-r--r--lisp/calc/calc-units.el647
1 files changed, 321 insertions, 326 deletions
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index 65640c701de..c86b53c86e6 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -1,6 +1,9 @@
1;; Calculator for GNU Emacs, part II [calc-units.el] 1;;; calc-units.el --- unit conversion functions for Calc
2
2;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. 3;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
3;; Written by Dave Gillespie, daveg@synaptics.com. 4
5;; Author: David Gillespie <daveg@synaptics.com>
6;; Maintainer: Colin Walters <walters@debian.org>
4 7
5;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
6 9
@@ -19,7 +22,9 @@
19;; file named COPYING. Among other things, the copyright notice 22;; file named COPYING. Among other things, the copyright notice
20;; and this notice must be preserved on all copies. 23;; and this notice must be preserved on all copies.
21 24
25;;; Commentary:
22 26
27;;; Code:
23 28
24;; This file is autoloaded from calc-ext.el. 29;; This file is autoloaded from calc-ext.el.
25(require 'calc-ext) 30(require 'calc-ext)
@@ -28,6 +33,245 @@
28 33
29(defun calc-Need-calc-units () nil) 34(defun calc-Need-calc-units () nil)
30 35
36;;; Units operations.
37
38;;; Units table last updated 9-Jan-91 by Ulrich Mueller (ulm@vsnhd1.cern.ch)
39;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov)
40
41(defvar math-standard-units
42 '( ;; Length
43 ( m nil "*Meter" )
44 ( in "2.54 cm" "Inch" )
45 ( ft "12 in" "Foot" )
46 ( yd "3 ft" "Yard" )
47 ( mi "5280 ft" "Mile" )
48 ( au "1.495979e11 m" "Astronomical Unit" )
49 ( lyr "9460536207068016 m" "Light Year" )
50 ( pc "206264.80625 au" "Parsec" )
51 ( nmi "1852 m" "Nautical Mile" )
52 ( fath "6 ft" "Fathom" )
53 ( u "1 um" "Micron" )
54 ( mil "in/1000" "Mil" )
55 ( point "in/72" "Point (1/72 inch)" )
56 ( tpt "in/72.27" "Point (TeX conventions)" )
57 ( Ang "1e-10 m" "Angstrom" )
58 ( mfi "mi+ft+in" "Miles + feet + inches" )
59
60 ;; Area
61 ( hect "10000 m^2" "*Hectare" )
62 ( acre "mi^2 / 640" "Acre" )
63 ( b "1e-28 m^2" "Barn" )
64
65 ;; Volume
66 ( l "1e-3 m^3" "*Liter" )
67 ( L "1e-3 m^3" "Liter" )
68 ( gal "4 qt" "US Gallon" )
69 ( qt "2 pt" "Quart" )
70 ( pt "2 cup" "Pint" )
71 ( cup "8 ozfl" "Cup" )
72 ( ozfl "2 tbsp" "Fluid Ounce" )
73 ( floz "2 tbsp" "Fluid Ounce" )
74 ( tbsp "3 tsp" "Tablespoon" )
75 ( tsp "4.92892159375 ml" "Teaspoon" )
76 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" )
77 ( galC "4.54609 l" "Canadian Gallon" )
78 ( galUK "4.546092 l" "UK Gallon" )
79
80 ;; Time
81 ( s nil "*Second" )
82 ( sec "s" "Second" )
83 ( min "60 s" "Minute" )
84 ( hr "60 min" "Hour" )
85 ( day "24 hr" "Day" )
86 ( wk "7 day" "Week" )
87 ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" )
88 ( yr "365.25 day" "Year" )
89 ( Hz "1/s" "Hertz" )
90
91 ;; Speed
92 ( mph "mi/hr" "*Miles per hour" )
93 ( kph "km/hr" "Kilometers per hour" )
94 ( knot "nmi/hr" "Knot" )
95 ( c "2.99792458e8 m/s" "Speed of light" )
96
97 ;; Acceleration
98 ( ga "9.80665 m/s^2" "*\"g\" acceleration" )
99
100 ;; Mass
101 ( g nil "*Gram" )
102 ( lb "16 oz" "Pound (mass)" )
103 ( oz "28.349523125 g" "Ounce (mass)" )
104 ( ton "2000 lb" "Ton" )
105 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
106 ( t "1000 kg" "Metric ton" )
107 ( tonUK "1016.0469088 kg" "UK ton" )
108 ( lbt "12 ozt" "Troy pound" )
109 ( ozt "31.103475 g" "Troy ounce" )
110 ( ct ".2 g" "Carat" )
111 ( amu "1.6605402e-24 g" "Unified atomic mass" )
112
113 ;; Force
114 ( N "m kg/s^2" "*Newton" )
115 ( dyn "1e-5 N" "Dyne" )
116 ( gf "ga g" "Gram (force)" )
117 ( lbf "4.44822161526 N" "Pound (force)" )
118 ( kip "1000 lbf" "Kilopound (force)" )
119 ( pdl "0.138255 N" "Poundal" )
120
121 ;; Energy
122 ( J "N m" "*Joule" )
123 ( erg "1e-7 J" "Erg" )
124 ( cal "4.1868 J" "International Table Calorie" )
125 ( Btu "1055.05585262 J" "International Table Btu" )
126 ( eV "ech V" "Electron volt" )
127 ( ev "eV" "Electron volt" )
128 ( therm "105506000 J" "EEC therm" )
129 ( invcm "h c/cm" "Energy in inverse centimeters" )
130 ( Kayser "invcm" "Kayser (inverse centimeter energy)" )
131 ( men "100/invcm" "Inverse energy in meters" )
132 ( Hzen "h Hz" "Energy in Hertz")
133 ( Ken "k K" "Energy in Kelvins")
134 ;; ( invcm "eV / 8065.47835185" "Energy in inverse centimeters" )
135 ;; ( Hzen "eV / 2.41796958004e14" "Energy in Hertz")
136 ;; ( Ken "eV / 11604.7967327" "Energy in Kelvins")
137
138 ;; Power
139 ( W "J/s" "*Watt" )
140 ( hp "745.7 W" "Horsepower" )
141
142 ;; Temperature
143 ( K nil "*Degree Kelvin" K )
144 ( dK "K" "Degree Kelvin" K )
145 ( degK "K" "Degree Kelvin" K )
146 ( dC "K" "Degree Celsius" C )
147 ( degC "K" "Degree Celsius" C )
148 ( dF "(5/9) K" "Degree Fahrenheit" F )
149 ( degF "(5/9) K" "Degree Fahrenheit" F )
150
151 ;; Pressure
152 ( Pa "N/m^2" "*Pascal" )
153 ( bar "1e5 Pa" "Bar" )
154 ( atm "101325 Pa" "Standard atmosphere" )
155 ( torr "atm/760" "Torr" )
156 ( mHg "1000 torr" "Meter of mercury" )
157 ( inHg "25.4 mmHg" "Inch of mercury" )
158 ( inH2O "248.84 Pa" "Inch of water" )
159 ( psi "6894.75729317 Pa" "Pound per square inch" )
160
161 ;; Viscosity
162 ( P "0.1 Pa s" "*Poise" )
163 ( St "1e-4 m^2/s" "Stokes" )
164
165 ;; Electromagnetism
166 ( A nil "*Ampere" )
167 ( C "A s" "Coulomb" )
168 ( Fdy "ech Nav" "Faraday" )
169 ( e "1.60217733e-19 C" "Elementary charge" )
170 ( ech "1.60217733e-19 C" "Elementary charge" )
171 ( V "W/A" "Volt" )
172 ( ohm "V/A" "Ohm" )
173 ( mho "A/V" "Mho" )
174 ( S "A/V" "Siemens" )
175 ( F "C/V" "Farad" )
176 ( H "Wb/A" "Henry" )
177 ( T "Wb/m^2" "Tesla" )
178 ( G "1e-4 T" "Gauss" )
179 ( Wb "V s" "Weber" )
180
181 ;; Luminous intensity
182 ( cd nil "*Candela" )
183 ( sb "1e4 cd/m^2" "Stilb" )
184 ( lm "cd sr" "Lumen" )
185 ( lx "lm/m^2" "Lux" )
186 ( ph "1e4 lx" "Phot" )
187 ( fc "10.76 lx" "Footcandle" )
188 ( lam "1e4 lm/m^2" "Lambert" )
189 ( flam "1.07639104e-3 lam" "Footlambert" )
190
191 ;; Radioactivity
192 ( Bq "1/s" "*Becquerel" )
193 ( Ci "3.7e10 Bq" "Curie" )
194 ( Gy "J/kg" "Gray" )
195 ( Sv "Gy" "Sievert" )
196 ( R "2.58e-4 C/kg" "Roentgen" )
197 ( rd ".01 Gy" "Rad" )
198 ( rem "rd" "Rem" )
199
200 ;; Amount of substance
201 ( mol nil "*Mole" )
202
203 ;; Plane angle
204 ( rad nil "*Radian" )
205 ( circ "2 pi rad" "Full circle" )
206 ( rev "circ" "Full revolution" )
207 ( deg "circ/360" "Degree" )
208 ( arcmin "deg/60" "Arc minute" )
209 ( arcsec "arcmin/60" "Arc second" )
210 ( grad "circ/400" "Grade" )
211 ( rpm "rev/min" "Revolutions per minute" )
212
213 ;; Solid angle
214 ( sr nil "*Steradian" )
215
216 ;; Other physical quantities (Physics Letters B239, 1 (1990))
217 ( h "6.6260755e-34 J s" "*Planck's constant" )
218 ( hbar "h / 2 pi" "Planck's constant" )
219 ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" )
220 ( Grav "6.67259e-11 N m^2/kg^2" "Gravitational constant" )
221 ( Nav "6.0221367e23 / mol" "Avagadro's constant" )
222 ( me "0.51099906 MeV/c^2" "Electron rest mass" )
223 ( mp "1.007276470 amu" "Proton rest mass" )
224 ( mn "1.008664904 amu" "Neutron rest mass" )
225 ( mu "0.113428913 amu" "Muon rest mass" )
226 ( Ryd "1.0973731571e5 invcm" "Rydberg's constant" )
227 ( k "1.3806513e-23 J/K" "Boltzmann's constant" )
228 ( fsc "1 / 137.0359895" "Fine structure constant" )
229 ( muB "5.78838263e-11 MeV/T" "Bohr magneton" )
230 ( muN "3.15245166e-14 MeV/T" "Nuclear magneton" )
231 ( mue "1.001159652193 muB" "Electron magnetic moment" )
232 ( mup "2.792847386 muN" "Proton magnetic moment" )
233 ( R0 "Nav k" "Molar gas constant" )
234 ( V0 "22.413992 L/mol" "Standard volume of ideal gas" )))
235
236
237(defvar math-additional-units nil
238 "*Additional units table for user-defined units.
239Must be formatted like math-standard-units.
240If this is changed, be sure to set math-units-table to nil to ensure
241that the combined units table will be rebuilt.")
242
243(defvar math-unit-prefixes
244 '( ( ?E (float 1 18) "Exa" )
245 ( ?P (float 1 15) "Peta" )
246 ( ?T (float 1 12) "Tera" )
247 ( ?G (float 1 9) "Giga" )
248 ( ?M (float 1 6) "Mega" )
249 ( ?k (float 1 3) "Kilo" )
250 ( ?K (float 1 3) "Kilo" )
251 ( ?h (float 1 2) "Hecto" )
252 ( ?H (float 1 2) "Hecto" )
253 ( ?D (float 1 1) "Deka" )
254 ( 0 (float 1 0) nil )
255 ( ?d (float 1 -1) "Deci" )
256 ( ?c (float 1 -2) "Centi" )
257 ( ?m (float 1 -3) "Milli" )
258 ( ?u (float 1 -6) "Micro" )
259 ( ?n (float 1 -9) "Nano" )
260 ( ?p (float 1 -12) "Pico" )
261 ( ?f (float 1 -15) "Femto" )
262 ( ?a (float 1 -18) "Atto" )))
263
264(defvar math-standard-units-systems
265 '( ( base nil )
266 ( si ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) )
267 ( mks ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) )
268 ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) )))
269
270(defvar math-units-table nil
271 "Internal units table derived from math-defined-units.
272Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
273
274(defvar math-units-table-buffer-valid nil)
31 275
32;;; Units commands. 276;;; Units commands.
33 277
@@ -46,12 +290,12 @@
46 (pos (if (= num 0) 10 num)) 290 (pos (if (= num 0) 10 num))
47 (units (calc-var-value 'var-Units)) 291 (units (calc-var-value 'var-Units))
48 (expr (calc-top-n 1))) 292 (expr (calc-top-n 1)))
49 (or (and (>= num 0) (<= num 9)) 293 (unless (and (>= num 0) (<= num 9))
50 (error "Bad unit number")) 294 (errunless "Bad unit number"))
51 (or (math-vectorp units) 295 (unless (math-vectorp units)
52 (error "No \"quick units\" are defined")) 296 (errunless "No \"quick units\" are defined"))
53 (or (< pos (length units)) 297 (unless (< pos (length units))
54 (error "Unit number %d not defined" pos)) 298 (errunless "Unit number %d not defined" pos))
55 (if (math-units-in-expr-p expr nil) 299 (if (math-units-in-expr-p expr nil)
56 (calc-enter-result 1 (format "cun%d" num) 300 (calc-enter-result 1 (format "cun%d" num)
57 (math-convert-units expr (nth pos units))) 301 (math-convert-units expr (nth pos units)))
@@ -65,31 +309,31 @@
65 (let ((expr (calc-top-n 1)) 309 (let ((expr (calc-top-n 1))
66 (uoldname nil) 310 (uoldname nil)
67 unew) 311 unew)
68 (or (math-units-in-expr-p expr t) 312 (unless (math-units-in-expr-p expr t)
69 (let ((uold (or old-units 313 (let ((uold (or old-units
70 (progn 314 (progn
71 (setq uoldname (read-string "Old units: ")) 315 (setq uoldname (read-string "Old units: "))
72 (if (equal uoldname "") 316 (if (equal uoldname "")
73 (progn 317 (progn
74 (setq uoldname "1") 318 (setq uoldname "1")
75 1) 319 1)
76 (if (string-match "\\` */" uoldname) 320 (if (string-match "\\` */" uoldname)
77 (setq uoldname (concat "1" uoldname))) 321 (setq uoldname (concat "1" uoldname)))
78 (math-read-expr uoldname)))))) 322 (math-read-expr uoldname))))))
79 (if (eq (car-safe uold) 'error) 323 (when (eq (car-safe uold) 'error)
80 (error "Bad format in units expression: %s" (nth 1 uold))) 324 (error "Bad format in units expression: %s" (nth 1 uold)))
81 (setq expr (math-mul expr uold)))) 325 (setq expr (math-mul expr uold))))
82 (or new-units 326 (unless new-units
83 (setq new-units (read-string (if uoldname 327 (setq new-units (read-string (if uoldname
84 (concat "Old units: " 328 (concat "Old units: "
85 uoldname 329 uoldname
86 ", new units: ") 330 ", new units: ")
87 "New units: ")))) 331 "New units: "))))
88 (if (string-match "\\` */" new-units) 332 (when (string-match "\\` */" new-units)
89 (setq new-units (concat "1" new-units))) 333 (setq new-units (concat "1" new-units)))
90 (setq units (math-read-expr new-units)) 334 (setq units (math-read-expr new-units))
91 (if (eq (car-safe units) 'error) 335 (when (eq (car-safe units) 'error)
92 (error "Bad format in units expression: %s" (nth 2 units))) 336 (error "Bad format in units expression: %s" (nth 2 units)))
93 (let ((unew (math-units-in-expr-p units t)) 337 (let ((unew (math-units-in-expr-p units t))
94 (std (and (eq (car-safe units) 'var) 338 (std (and (eq (car-safe units) 'var)
95 (assq (nth 1 units) math-standard-units-systems)))) 339 (assq (nth 1 units) math-standard-units-systems))))
@@ -97,8 +341,8 @@
97 (calc-enter-result 1 "cvun" (math-simplify-units 341 (calc-enter-result 1 "cvun" (math-simplify-units
98 (math-to-standard-units expr 342 (math-to-standard-units expr
99 (nth 1 std)))) 343 (nth 1 std))))
100 (or unew 344 (unless unew
101 (error "No units specified")) 345 (error "No units specified"))
102 (calc-enter-result 1 "cvun" 346 (calc-enter-result 1 "cvun"
103 (math-convert-units 347 (math-convert-units
104 expr units 348 expr units
@@ -109,8 +353,8 @@
109 (calc-wrapper 353 (calc-wrapper
110 (calc-change-mode 'calc-autorange-units arg nil t) 354 (calc-change-mode 'calc-autorange-units arg nil t)
111 (message (if calc-autorange-units 355 (message (if calc-autorange-units
112 "Adjusting target unit prefix automatically." 356 "Adjusting target unit prefix automatically"
113 "Using target units exactly.")))) 357 "Using target units exactly"))))
114 358
115(defun calc-convert-temperature (&optional old-units new-units) 359(defun calc-convert-temperature (&optional old-units new-units)
116 (interactive) 360 (interactive)
@@ -131,8 +375,8 @@
131 (math-read-expr 375 (math-read-expr
132 (setq uoldname (read-string 376 (setq uoldname (read-string
133 "Old temperature units: "))))))) 377 "Old temperature units: ")))))))
134 (if (eq (car-safe uold) 'error) 378 (when (eq (car-safe uold) 'error)
135 (error "Bad format in units expression: %s" (nth 2 uold))) 379 (error "Bad format in units expression: %s" (nth 2 uold)))
136 (or (math-units-in-expr-p expr nil) 380 (or (math-units-in-expr-p expr nil)
137 (setq expr (math-mul expr uold))) 381 (setq expr (math-mul expr uold)))
138 (setq unew (or new-units 382 (setq unew (or new-units
@@ -142,8 +386,8 @@
142 uoldname 386 uoldname
143 ", new units: ") 387 ", new units: ")
144 "New temperature units: "))))) 388 "New temperature units: ")))))
145 (if (eq (car-safe unew) 'error) 389 (when (eq (car-safe unew) 'error)
146 (error "Bad format in units expression: %s" (nth 2 unew))) 390 (error "Bad format in units expression: %s" (nth 2 unew)))
147 (calc-enter-result 1 "cvtm" (math-simplify-units 391 (calc-enter-result 1 "cvtm" (math-simplify-units
148 (math-convert-temperature expr uold unew 392 (math-convert-temperature expr uold unew
149 uoldname)))))) 393 uoldname))))))
@@ -258,7 +502,7 @@
258 (interactive "P") 502 (interactive "P")
259 (and n (setq math-units-table-buffer-valid nil)) 503 (and n (setq math-units-table-buffer-valid nil))
260 (math-build-units-table-buffer t) 504 (math-build-units-table-buffer t)
261 (message (substitute-command-keys "Type \\[calc] to return to the Calculator."))) 505 (message (substitute-command-keys "Type \\[calc] to return to the Calculator")))
262 506
263(defun calc-define-unit (uname desc) 507(defun calc-define-unit (uname desc)
264 (interactive "SDefine unit name: \nsDescription: ") 508 (interactive "SDefine unit name: \nsDescription: ")
@@ -367,252 +611,6 @@
367 611
368 612
369 613
370
371
372;;; Units operations.
373
374;;; Units table last updated 9-Jan-91 by Ulrich Mueller (ulm@vsnhd1.cern.ch)
375;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov)
376
377(defvar math-standard-units
378 '( ;; Length
379 ( m nil "*Meter" )
380 ( in "2.54 cm" "Inch" )
381 ( ft "12 in" "Foot" )
382 ( yd "3 ft" "Yard" )
383 ( mi "5280 ft" "Mile" )
384 ( au "1.495979e11 m" "Astronomical Unit" )
385 ( lyr "9460536207068016 m" "Light Year" )
386 ( pc "206264.80625 au" "Parsec" )
387 ( nmi "1852 m" "Nautical Mile" )
388 ( fath "6 ft" "Fathom" )
389 ( u "1 um" "Micron" )
390 ( mil "in/1000" "Mil" )
391 ( point "in/72" "Point (1/72 inch)" )
392 ( tpt "in/72.27" "Point (TeX conventions)" )
393 ( Ang "1e-10 m" "Angstrom" )
394 ( mfi "mi+ft+in" "Miles + feet + inches" )
395
396 ;; Area
397 ( hect "10000 m^2" "*Hectare" )
398 ( acre "mi^2 / 640" "Acre" )
399 ( b "1e-28 m^2" "Barn" )
400
401 ;; Volume
402 ( l "1e-3 m^3" "*Liter" )
403 ( L "1e-3 m^3" "Liter" )
404 ( gal "4 qt" "US Gallon" )
405 ( qt "2 pt" "Quart" )
406 ( pt "2 cup" "Pint" )
407 ( cup "8 ozfl" "Cup" )
408 ( ozfl "2 tbsp" "Fluid Ounce" )
409 ( floz "2 tbsp" "Fluid Ounce" )
410 ( tbsp "3 tsp" "Tablespoon" )
411 ( tsp "4.92892159375 ml" "Teaspoon" )
412 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" )
413 ( galC "4.54609 l" "Canadian Gallon" )
414 ( galUK "4.546092 l" "UK Gallon" )
415
416 ;; Time
417 ( s nil "*Second" )
418 ( sec "s" "Second" )
419 ( min "60 s" "Minute" )
420 ( hr "60 min" "Hour" )
421 ( day "24 hr" "Day" )
422 ( wk "7 day" "Week" )
423 ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" )
424 ( yr "365.25 day" "Year" )
425 ( Hz "1/s" "Hertz" )
426
427 ;; Speed
428 ( mph "mi/hr" "*Miles per hour" )
429 ( kph "km/hr" "Kilometers per hour" )
430 ( knot "nmi/hr" "Knot" )
431 ( c "2.99792458e8 m/s" "Speed of light" )
432
433 ;; Acceleration
434 ( ga "9.80665 m/s^2" "*\"g\" acceleration" )
435
436 ;; Mass
437 ( g nil "*Gram" )
438 ( lb "16 oz" "Pound (mass)" )
439 ( oz "28.349523125 g" "Ounce (mass)" )
440 ( ton "2000 lb" "Ton" )
441 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
442 ( t "1000 kg" "Metric ton" )
443 ( tonUK "1016.0469088 kg" "UK ton" )
444 ( lbt "12 ozt" "Troy pound" )
445 ( ozt "31.103475 g" "Troy ounce" )
446 ( ct ".2 g" "Carat" )
447 ( amu "1.6605402e-24 g" "Unified atomic mass" )
448
449 ;; Force
450 ( N "m kg/s^2" "*Newton" )
451 ( dyn "1e-5 N" "Dyne" )
452 ( gf "ga g" "Gram (force)" )
453 ( lbf "4.44822161526 N" "Pound (force)" )
454 ( kip "1000 lbf" "Kilopound (force)" )
455 ( pdl "0.138255 N" "Poundal" )
456
457 ;; Energy
458 ( J "N m" "*Joule" )
459 ( erg "1e-7 J" "Erg" )
460 ( cal "4.1868 J" "International Table Calorie" )
461 ( Btu "1055.05585262 J" "International Table Btu" )
462 ( eV "ech V" "Electron volt" )
463 ( ev "eV" "Electron volt" )
464 ( therm "105506000 J" "EEC therm" )
465 ( invcm "h c/cm" "Energy in inverse centimeters" )
466 ( Kayser "invcm" "Kayser (inverse centimeter energy)" )
467 ( men "100/invcm" "Inverse energy in meters" )
468 ( Hzen "h Hz" "Energy in Hertz")
469 ( Ken "k K" "Energy in Kelvins")
470 ;; ( invcm "eV / 8065.47835185" "Energy in inverse centimeters" )
471 ;; ( Hzen "eV / 2.41796958004e14" "Energy in Hertz")
472 ;; ( Ken "eV / 11604.7967327" "Energy in Kelvins")
473
474 ;; Power
475 ( W "J/s" "*Watt" )
476 ( hp "745.7 W" "Horsepower" )
477
478 ;; Temperature
479 ( K nil "*Degree Kelvin" K )
480 ( dK "K" "Degree Kelvin" K )
481 ( degK "K" "Degree Kelvin" K )
482 ( dC "K" "Degree Celsius" C )
483 ( degC "K" "Degree Celsius" C )
484 ( dF "(5/9) K" "Degree Fahrenheit" F )
485 ( degF "(5/9) K" "Degree Fahrenheit" F )
486
487 ;; Pressure
488 ( Pa "N/m^2" "*Pascal" )
489 ( bar "1e5 Pa" "Bar" )
490 ( atm "101325 Pa" "Standard atmosphere" )
491 ( torr "atm/760" "Torr" )
492 ( mHg "1000 torr" "Meter of mercury" )
493 ( inHg "25.4 mmHg" "Inch of mercury" )
494 ( inH2O "248.84 Pa" "Inch of water" )
495 ( psi "6894.75729317 Pa" "Pound per square inch" )
496
497 ;; Viscosity
498 ( P "0.1 Pa s" "*Poise" )
499 ( St "1e-4 m^2/s" "Stokes" )
500
501 ;; Electromagnetism
502 ( A nil "*Ampere" )
503 ( C "A s" "Coulomb" )
504 ( Fdy "ech Nav" "Faraday" )
505 ( e "1.60217733e-19 C" "Elementary charge" )
506 ( ech "1.60217733e-19 C" "Elementary charge" )
507 ( V "W/A" "Volt" )
508 ( ohm "V/A" "Ohm" )
509 ( mho "A/V" "Mho" )
510 ( S "A/V" "Siemens" )
511 ( F "C/V" "Farad" )
512 ( H "Wb/A" "Henry" )
513 ( T "Wb/m^2" "Tesla" )
514 ( G "1e-4 T" "Gauss" )
515 ( Wb "V s" "Weber" )
516
517 ;; Luminous intensity
518 ( cd nil "*Candela" )
519 ( sb "1e4 cd/m^2" "Stilb" )
520 ( lm "cd sr" "Lumen" )
521 ( lx "lm/m^2" "Lux" )
522 ( ph "1e4 lx" "Phot" )
523 ( fc "10.76 lx" "Footcandle" )
524 ( lam "1e4 lm/m^2" "Lambert" )
525 ( flam "1.07639104e-3 lam" "Footlambert" )
526
527 ;; Radioactivity
528 ( Bq "1/s" "*Becquerel" )
529 ( Ci "3.7e10 Bq" "Curie" )
530 ( Gy "J/kg" "Gray" )
531 ( Sv "Gy" "Sievert" )
532 ( R "2.58e-4 C/kg" "Roentgen" )
533 ( rd ".01 Gy" "Rad" )
534 ( rem "rd" "Rem" )
535
536 ;; Amount of substance
537 ( mol nil "*Mole" )
538
539 ;; Plane angle
540 ( rad nil "*Radian" )
541 ( circ "2 pi rad" "Full circle" )
542 ( rev "circ" "Full revolution" )
543 ( deg "circ/360" "Degree" )
544 ( arcmin "deg/60" "Arc minute" )
545 ( arcsec "arcmin/60" "Arc second" )
546 ( grad "circ/400" "Grade" )
547 ( rpm "rev/min" "Revolutions per minute" )
548
549 ;; Solid angle
550 ( sr nil "*Steradian" )
551
552 ;; Other physical quantities (Physics Letters B239, 1 (1990))
553 ( h "6.6260755e-34 J s" "*Planck's constant" )
554 ( hbar "h / 2 pi" "Planck's constant" )
555 ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" )
556 ( Grav "6.67259e-11 N m^2/kg^2" "Gravitational constant" )
557 ( Nav "6.0221367e23 / mol" "Avagadro's constant" )
558 ( me "0.51099906 MeV/c^2" "Electron rest mass" )
559 ( mp "1.007276470 amu" "Proton rest mass" )
560 ( mn "1.008664904 amu" "Neutron rest mass" )
561 ( mu "0.113428913 amu" "Muon rest mass" )
562 ( Ryd "1.0973731571e5 invcm" "Rydberg's constant" )
563 ( k "1.3806513e-23 J/K" "Boltzmann's constant" )
564 ( fsc "1 / 137.0359895" "Fine structure constant" )
565 ( muB "5.78838263e-11 MeV/T" "Bohr magneton" )
566 ( muN "3.15245166e-14 MeV/T" "Nuclear magneton" )
567 ( mue "1.001159652193 muB" "Electron magnetic moment" )
568 ( mup "2.792847386 muN" "Proton magnetic moment" )
569 ( R0 "Nav k" "Molar gas constant" )
570 ( V0 "22.413992 L/mol" "Standard volume of ideal gas" )
571))
572
573
574(defvar math-additional-units nil
575 "*Additional units table for user-defined units.
576Must be formatted like math-standard-units.
577If this is changed, be sure to set math-units-table to nil to ensure
578that the combined units table will be rebuilt.")
579
580(defvar math-unit-prefixes
581 '( ( ?E (float 1 18) "Exa" )
582 ( ?P (float 1 15) "Peta" )
583 ( ?T (float 1 12) "Tera" )
584 ( ?G (float 1 9) "Giga" )
585 ( ?M (float 1 6) "Mega" )
586 ( ?k (float 1 3) "Kilo" )
587 ( ?K (float 1 3) "Kilo" )
588 ( ?h (float 1 2) "Hecto" )
589 ( ?H (float 1 2) "Hecto" )
590 ( ?D (float 1 1) "Deka" )
591 ( 0 (float 1 0) nil )
592 ( ?d (float 1 -1) "Deci" )
593 ( ?c (float 1 -2) "Centi" )
594 ( ?m (float 1 -3) "Milli" )
595 ( ?u (float 1 -6) "Micro" )
596 ( ?n (float 1 -9) "Nano" )
597 ( ?p (float 1 -12) "Pico" )
598 ( ?f (float 1 -15) "Femto" )
599 ( ?a (float 1 -18) "Atto" )
600))
601
602(defvar math-standard-units-systems
603 '( ( base nil )
604 ( si ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) )
605 ( mks ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) )
606 ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) )
607))
608
609(defvar math-units-table nil
610 "Internal units table derived from math-defined-units.
611Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
612
613(defvar math-units-table-buffer-valid nil)
614
615
616(defun math-build-units-table () 614(defun math-build-units-table ()
617 (or math-units-table 615 (or math-units-table
618 (let* ((combined-units (append math-additional-units 616 (let* ((combined-units (append math-additional-units
@@ -803,6 +801,7 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
803 expr 801 expr
804 (list '* expr units))))) 802 (list '* expr units)))))
805 803
804(defvar math-decompose-units-cache nil)
806(defun math-decompose-units (units) 805(defun math-decompose-units (units)
807 (let ((u (math-check-unit-name units))) 806 (let ((u (math-check-unit-name units)))
808 (and u (eq (car-safe (nth 1 u)) '+) 807 (and u (eq (car-safe (nth 1 u)) '+)
@@ -821,8 +820,8 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
821 (setq ulist (cons (math-decompose-unit-part utemp) ulist) 820 (setq ulist (cons (math-decompose-unit-part utemp) ulist)
822 utemp ulist) 821 utemp ulist)
823 (while (setq utemp (cdr utemp)) 822 (while (setq utemp (cdr utemp))
824 (or (equal (nth 2 (car utemp)) (nth 2 (car ulist))) 823 (unless (equal (nth 2 (car utemp)) (nth 2 (car ulist)))
825 (error "Inconsistent units in sum"))) 824 (error "Inconsistent units in sum")))
826 (setq math-decompose-units-cache 825 (setq math-decompose-units-cache
827 (cons entry 826 (cons entry
828 (sort ulist 827 (sort ulist
@@ -831,7 +830,6 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
831 (not (Math-lessp (nth 1 x) 830 (not (Math-lessp (nth 1 x)
832 (nth 1 y)))))))))) 831 (nth 1 y))))))))))
833 (cdr math-decompose-units-cache)))) 832 (cdr math-decompose-units-cache))))
834(setq math-decompose-units-cache nil)
835 833
836(defun math-decompose-unit-part (unit) 834(defun math-decompose-unit-part (unit)
837 (cons unit 835 (cons unit
@@ -875,10 +873,10 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
875 (math-pow (math-div (car compat) new-units) 873 (math-pow (math-div (car compat) new-units)
876 (cdr compat)) 874 (cdr compat))
877 nil)))) 875 nil))))
878 (if (setq unit-list (math-decompose-units new-units)) 876 (when (setq unit-list (math-decompose-units new-units))
879 (setq new-units (nth 2 (car unit-list)))) 877 (setq new-units (nth 2 (car unit-list))))
880 (if (eq (car-safe expr) '+) 878 (when (eq (car-safe expr) '+)
881 (setq expr (math-simplify-units expr))) 879 (setq expr (math-simplify-units expr)))
882 (if (math-units-in-expr-p expr t) 880 (if (math-units-in-expr-p expr t)
883 (math-convert-units-rec expr) 881 (math-convert-units-rec expr)
884 (math-apply-units (math-to-standard-units 882 (math-apply-units (math-to-standard-units
@@ -903,10 +901,10 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
903 (error "Inconsistent temperature units")) 901 (error "Inconsistent temperature units"))
904 units)) 902 units))
905 (unew (math-check-unit-name new))) 903 (unew (math-check-unit-name new)))
906 (or (and (consp unew) (nth 3 unew)) 904 (unless (and (consp unew) (nth 3 unew))
907 (error "Not a valid temperature unit")) 905 (error "Not a valid temperature unit"))
908 (or (and (consp uold) (nth 3 uold)) 906 (unless (and (consp uold) (nth 3 uold))
909 (error "Not a pure temperature expression")) 907 (error "Not a pure temperature expression"))
910 (let ((v (car uold))) 908 (let ((v (car uold)))
911 (setq expr (list '/ expr (list 'var v 909 (setq expr (list '/ expr (list 'var v
912 (intern (concat "var-" 910 (intern (concat "var-"
@@ -934,7 +932,7 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
934 (let ((math-simplifying-units t) 932 (let ((math-simplifying-units t)
935 (calc-matrix-mode 'scalar)) 933 (calc-matrix-mode 'scalar))
936 (math-simplify a))) 934 (math-simplify a)))
937(defalias calcFunc-usimplify 'math-simplify-units) 935(defalias 'calcFunc-usimplify 'math-simplify-units)
938 936
939(math-defsimplify (+ -) 937(math-defsimplify (+ -)
940 (and math-simplifying-units 938 (and math-simplifying-units
@@ -1049,26 +1047,24 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
1049 (let ((n (car np)) 1047 (let ((n (car np))
1050 d dd temp) 1048 d dd temp)
1051 (while (eq (car-safe (setq d (car dp))) '*) 1049 (while (eq (car-safe (setq d (car dp))) '*)
1052 (if (setq temp (math-simplify-units-quotient n (nth 1 d))) 1050 (when (setq temp (math-simplify-units-quotient n (nth 1 d)))
1053 (progn 1051 (setcar np (setq n temp))
1054 (setcar np (setq n temp)) 1052 (setcar (cdr d) 1))
1055 (setcar (cdr d) 1)))
1056 (setq dp (cdr (cdr d)))) 1053 (setq dp (cdr (cdr d))))
1057 (if (setq temp (math-simplify-units-quotient n d)) 1054 (when (setq temp (math-simplify-units-quotient n d))
1058 (progn 1055 (setcar np (setq n temp))
1059 (setcar np (setq n temp)) 1056 (setcar dp 1))))
1060 (setcar dp 1)))))
1061 1057
1062;; Simplify, e.g., "in / cm" to "2.54" in a units expression. 1058;; Simplify, e.g., "in / cm" to "2.54" in a units expression.
1063(defun math-simplify-units-quotient (n d) 1059(defun math-simplify-units-quotient (n d)
1064 (let ((pow1 1) 1060 (let ((pow1 1)
1065 (pow2 1)) 1061 (pow2 1))
1066 (and (eq (car-safe n) '^) 1062 (when (and (eq (car-safe n) '^)
1067 (integerp (nth 2 n)) 1063 (integerp (nth 2 n)))
1068 (setq pow1 (nth 2 n) n (nth 1 n))) 1064 (setq pow1 (nth 2 n) n (nth 1 n)))
1069 (and (eq (car-safe d) '^) 1065 (when (and (eq (car-safe d) '^)
1070 (integerp (nth 2 d)) 1066 (integerp (nth 2 d)))
1071 (setq pow2 (nth 2 d) d (nth 1 d))) 1067 (setq pow2 (nth 2 d) d (nth 1 d)))
1072 (let ((un (math-check-unit-name n)) 1068 (let ((un (math-check-unit-name n))
1073 (ud (math-check-unit-name d))) 1069 (ud (math-check-unit-name d)))
1074 (and un ud 1070 (and un ud
@@ -1229,16 +1225,15 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
1229 (while uptr 1225 (while uptr
1230 (setq u (car uptr) 1226 (setq u (car uptr)
1231 name (nth 2 u)) 1227 name (nth 2 u))
1232 (if (eq (car u) 'm) 1228 (when (eq (car u) 'm)
1233 (setq std t)) 1229 (setq std t))
1234 (setq shadowed (and std (assq (car u) math-additional-units))) 1230 (setq shadowed (and std (assq (car u) math-additional-units)))
1235 (if (and name 1231 (when (and name
1236 (> (length name) 1) 1232 (> (length name) 1)
1237 (eq (aref name 0) ?\*)) 1233 (eq (aref name 0) ?\*))
1238 (progn 1234 (unless (eq uptr math-units-table)
1239 (or (eq uptr math-units-table) 1235 (insert "\n"))
1240 (insert "\n")) 1236 (setq name (substring name 1)))
1241 (setq name (substring name 1))))
1242 (insert " ") 1237 (insert " ")
1243 (and shadowed (insert "(")) 1238 (and shadowed (insert "("))
1244 (insert (symbol-name (car u))) 1239 (insert (symbol-name (car u)))
@@ -1259,12 +1254,12 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
1259 (and shadowed (insert ")")) 1254 (and shadowed (insert ")"))
1260 (indent-to 41) 1255 (indent-to 41)
1261 (insert " ") 1256 (insert " ")
1262 (if name 1257 (when name
1263 (insert name)) 1258 (insert name))
1264 (if shadowed 1259 (if shadowed
1265 (insert " (redefined above)") 1260 (insert " (redefined above)")
1266 (or (nth 1 u) 1261 (unless (nth 1 u)
1267 (insert " (base unit)"))) 1262 (insert " (base unit)")))
1268 (insert "\n") 1263 (insert "\n")
1269 (setq uptr (cdr uptr))) 1264 (setq uptr (cdr uptr)))
1270 (insert "\n\nUnit Prefix Table:\n\n") 1265 (insert "\n\nUnit Prefix Table:\n\n")