summaryrefslogtreecommitdiff
path: root/lisp/calc
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/calc')
-rw-r--r--lisp/calc/calc-aent.el3
-rw-r--r--lisp/calc/calc-bin.el4
-rw-r--r--lisp/calc/calc-comb.el21
-rw-r--r--lisp/calc/calc-ext.el10
-rw-r--r--lisp/calc/calc-funcs.el263
-rw-r--r--lisp/calc/calc-math.el6
-rw-r--r--lisp/calc/calc-units.el298
-rw-r--r--lisp/calc/calc.el7
8 files changed, 339 insertions, 273 deletions
diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el
index e640eb5c438..ffd07bd8f2e 100644
--- a/lisp/calc/calc-aent.el
+++ b/lisp/calc/calc-aent.el
@@ -74,6 +74,9 @@
", "
(let ((calc-number-radix 8))
(math-format-value (car alg-exp) 1000))
+ ", "
+ (let ((calc-number-radix 2))
+ (math-format-value (car alg-exp) 1000))
(if (and (integerp (car alg-exp))
(> (car alg-exp) 0)
(< (car alg-exp) 127))
diff --git a/lisp/calc/calc-bin.el b/lisp/calc/calc-bin.el
index c58d0addd77..0f219272a5f 100644
--- a/lisp/calc/calc-bin.el
+++ b/lisp/calc/calc-bin.el
@@ -34,13 +34,13 @@
;;; Some useful numbers
(defconst math-bignum-logb-digit-size
- (eval-when-compile (logb math-bignum-digit-size))
+ (logb math-bignum-digit-size)
"The logb of the size of a bignum digit.
This is the largest value of B such that 2^B is less than
the size of a Calc bignum digit.")
(defconst math-bignum-digit-power-of-two
- (eval-when-compile (expt 2 (logb math-bignum-digit-size)))
+ (expt 2 (logb math-bignum-digit-size))
"The largest power of 2 less than the size of a Calc bignum digit.")
;;; b-prefix binary commands.
diff --git a/lisp/calc/calc-comb.el b/lisp/calc/calc-comb.el
index 90a0a20f5d6..b6182cd710e 100644
--- a/lisp/calc/calc-comb.el
+++ b/lisp/calc/calc-comb.el
@@ -295,17 +295,16 @@
;;; Factorial and related functions.
(defconst math-small-factorial-table
- (eval-when-compile
- (vector 1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800
- (math-read-number-simple "479001600")
- (math-read-number-simple "6227020800")
- (math-read-number-simple "87178291200")
- (math-read-number-simple "1307674368000")
- (math-read-number-simple "20922789888000")
- (math-read-number-simple "355687428096000")
- (math-read-number-simple "6402373705728000")
- (math-read-number-simple "121645100408832000")
- (math-read-number-simple "2432902008176640000"))))
+ (vector 1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800
+ (math-read-number-simple "479001600")
+ (math-read-number-simple "6227020800")
+ (math-read-number-simple "87178291200")
+ (math-read-number-simple "1307674368000")
+ (math-read-number-simple "20922789888000")
+ (math-read-number-simple "355687428096000")
+ (math-read-number-simple "6402373705728000")
+ (math-read-number-simple "121645100408832000")
+ (math-read-number-simple "2432902008176640000")))
(defun calcFunc-fact (n) ; [I I] [F F] [Public]
(let (temp)
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index 5a334778aa5..ab8f743eb34 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -1926,8 +1926,7 @@ calc-kill calc-kill-region calc-yank))))
;;; Betcha didn't know that pi = 16 atan(1/5) - 4 atan(1/239). [F] [Public]
(defconst math-approx-pi
- (eval-when-compile
- (math-read-number-simple "3.141592653589793238463"))
+ (math-read-number-simple "3.141592653589793238463")
"An approximation for pi.")
(math-defcache math-pi math-approx-pi
@@ -1962,7 +1961,7 @@ calc-kill calc-kill-region calc-yank))))
(math-sqrt-float (math-two-pi)))
(defconst math-approx-sqrt-e
- (eval-when-compile (math-read-number-simple "1.648721270700128146849"))
+ (math-read-number-simple "1.648721270700128146849")
"An approximation for sqrt(3).")
(math-defcache math-sqrt-e math-approx-sqrt-e
@@ -1976,9 +1975,8 @@ calc-kill calc-kill-region calc-yank))))
'(float 5 -1)))
(defconst math-approx-gamma-const
- (eval-when-compile
- (math-read-number-simple
- "0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495"))
+ (math-read-number-simple
+ "0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495")
"An approximation for gamma.")
(math-defcache math-gamma-const nil
diff --git a/lisp/calc/calc-funcs.el b/lisp/calc/calc-funcs.el
index b0209d39d73..d73d676bdef 100644
--- a/lisp/calc/calc-funcs.el
+++ b/lisp/calc/calc-funcs.el
@@ -569,53 +569,47 @@
(let* ((z (math-div '(float 8 0) x))
(y (math-sqr z))
(xx (math-add x
- (eval-when-compile
- (math-read-number-simple "-0.785398164"))))
+ (math-read-number-simple "-0.785398164")))
(a1 (math-poly-eval y
- (eval-when-compile
(list
(math-read-number-simple "0.0000002093887211")
(math-read-number-simple "-0.000002073370639")
(math-read-number-simple "0.00002734510407")
(math-read-number-simple "-0.001098628627")
- '(float 1 0)))))
+ '(float 1 0))))
(a2 (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "-0.0000000934935152")
- (math-read-number-simple "0.0000007621095161")
- (math-read-number-simple "-0.000006911147651")
- (math-read-number-simple "0.0001430488765")
- (math-read-number-simple "-0.01562499995")))))
+ (list
+ (math-read-number-simple "-0.0000000934935152")
+ (math-read-number-simple "0.0000007621095161")
+ (math-read-number-simple "-0.000006911147651")
+ (math-read-number-simple "0.0001430488765")
+ (math-read-number-simple "-0.01562499995"))))
(sc (math-sin-cos-raw xx)))
(if yflag
(setq sc (cons (math-neg (cdr sc)) (car sc))))
(math-mul (math-sqrt
- (math-div (eval-when-compile
- (math-read-number-simple "0.636619722"))
- x))
+ (math-div (math-read-number-simple "0.636619722")
+ x))
(math-sub (math-mul (cdr sc) a1)
(math-mul (car sc) (math-mul z a2))))))
(t
(let ((y (math-sqr x)))
(math-div (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "-184.9052456")
- (math-read-number-simple "77392.33017")
- (math-read-number-simple "-11214424.18")
- (math-read-number-simple "651619640.7")
- (math-read-number-simple "-13362590354.0")
- (math-read-number-simple "57568490574.0"))))
+ (list
+ (math-read-number-simple "-184.9052456")
+ (math-read-number-simple "77392.33017")
+ (math-read-number-simple "-11214424.18")
+ (math-read-number-simple "651619640.7")
+ (math-read-number-simple "-13362590354.0")
+ (math-read-number-simple "57568490574.0")))
(math-poly-eval y
- (eval-when-compile
- (list
- '(float 1 0)
- (math-read-number-simple "267.8532712")
- (math-read-number-simple "59272.64853")
- (math-read-number-simple "9494680.718")
- (math-read-number-simple "1029532985.0")
- (math-read-number-simple "57568490411.0")))))))))
+ (list
+ '(float 1 0)
+ (math-read-number-simple "267.8532712")
+ (math-read-number-simple "59272.64853")
+ (math-read-number-simple "9494680.718")
+ (math-read-number-simple "1029532985.0")
+ (math-read-number-simple "57568490411.0"))))))))
(defun math-besJ1 (x &optional yflag)
(cond ((and (math-negp (calcFunc-re x)) (not yflag))
@@ -623,32 +617,28 @@
((Math-lessp '(float 8 0) (math-abs-approx x))
(let* ((z (math-div '(float 8 0) x))
(y (math-sqr z))
- (xx (math-add x (eval-when-compile
- (math-read-number-simple "-2.356194491"))))
+ (xx (math-add x (math-read-number-simple "-2.356194491")))
(a1 (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "-0.000000240337019")
- (math-read-number-simple "0.000002457520174")
- (math-read-number-simple "-0.00003516396496")
- '(float 183105 -8)
- '(float 1 0)))))
+ (list
+ (math-read-number-simple "-0.000000240337019")
+ (math-read-number-simple "0.000002457520174")
+ (math-read-number-simple "-0.00003516396496")
+ '(float 183105 -8)
+ '(float 1 0))))
(a2 (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "0.000000105787412")
- (math-read-number-simple "-0.00000088228987")
- (math-read-number-simple "0.000008449199096")
- (math-read-number-simple "-0.0002002690873")
- (math-read-number-simple "0.04687499995")))))
+ (list
+ (math-read-number-simple "0.000000105787412")
+ (math-read-number-simple "-0.00000088228987")
+ (math-read-number-simple "0.000008449199096")
+ (math-read-number-simple "-0.0002002690873")
+ (math-read-number-simple "0.04687499995"))))
(sc (math-sin-cos-raw xx)))
(if yflag
(setq sc (cons (math-neg (cdr sc)) (car sc)))
(if (math-negp x)
(setq sc (cons (math-neg (car sc)) (math-neg (cdr sc))))))
(math-mul (math-sqrt (math-div
- (eval-when-compile
- (math-read-number-simple "0.636619722"))
+ (math-read-number-simple "0.636619722")
x))
(math-sub (math-mul (cdr sc) a1)
(math-mul (car sc) (math-mul z a2))))))
@@ -657,23 +647,21 @@
(math-mul
x
(math-div (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "-30.16036606")
- (math-read-number-simple "15704.4826")
- (math-read-number-simple "-2972611.439")
- (math-read-number-simple "242396853.1")
- (math-read-number-simple "-7895059235.0")
- (math-read-number-simple "72362614232.0"))))
+ (list
+ (math-read-number-simple "-30.16036606")
+ (math-read-number-simple "15704.4826")
+ (math-read-number-simple "-2972611.439")
+ (math-read-number-simple "242396853.1")
+ (math-read-number-simple "-7895059235.0")
+ (math-read-number-simple "72362614232.0")))
(math-poly-eval y
- (eval-when-compile
- (list
- '(float 1 0)
- (math-read-number-simple "376.9991397")
- (math-read-number-simple "99447.43394")
- (math-read-number-simple "18583304.74")
- (math-read-number-simple "2300535178.0")
- (math-read-number-simple "144725228442.0"))))))))))
+ (list
+ '(float 1 0)
+ (math-read-number-simple "376.9991397")
+ (math-read-number-simple "99447.43394")
+ (math-read-number-simple "18583304.74")
+ (math-read-number-simple "2300535178.0")
+ (math-read-number-simple "144725228442.0")))))))))
(defun calcFunc-besY (v x)
(math-inexact-result)
@@ -712,27 +700,24 @@
(defun math-besY0 (x)
(cond ((Math-lessp (math-abs-approx x) '(float 8 0))
(let ((y (math-sqr x)))
- (math-add
+ (math-add
(math-div (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "228.4622733")
- (math-read-number-simple "-86327.92757")
- (math-read-number-simple "10879881.29")
- (math-read-number-simple "-512359803.6")
- (math-read-number-simple "7062834065.0")
- (math-read-number-simple "-2957821389.0"))))
+ (list
+ (math-read-number-simple "228.4622733")
+ (math-read-number-simple "-86327.92757")
+ (math-read-number-simple "10879881.29")
+ (math-read-number-simple "-512359803.6")
+ (math-read-number-simple "7062834065.0")
+ (math-read-number-simple "-2957821389.0")))
(math-poly-eval y
- (eval-when-compile
- (list
- '(float 1 0)
- (math-read-number-simple "226.1030244")
- (math-read-number-simple "47447.2647")
- (math-read-number-simple "7189466.438")
- (math-read-number-simple "745249964.8")
- (math-read-number-simple "40076544269.0")))))
- (math-mul (eval-when-compile
- (math-read-number-simple "0.636619772"))
+ (list
+ '(float 1 0)
+ (math-read-number-simple "226.1030244")
+ (math-read-number-simple "47447.2647")
+ (math-read-number-simple "7189466.438")
+ (math-read-number-simple "745249964.8")
+ (math-read-number-simple "40076544269.0"))))
+ (math-mul (math-read-number-simple "0.636619772")
(math-mul (math-besJ0 x) (math-ln-raw x))))))
((math-negp (calcFunc-re x))
(math-add (math-besJ0 (math-neg x) t)
@@ -748,25 +733,23 @@
(math-mul
x
(math-div (math-poly-eval y
- (eval-when-compile
- (list
- (math-read-number-simple "8511.937935")
- (math-read-number-simple "-4237922.726")
- (math-read-number-simple "734926455.1")
- (math-read-number-simple "-51534381390.0")
- (math-read-number-simple "1275274390000.0")
- (math-read-number-simple "-4900604943000.0"))))
+ (list
+ (math-read-number-simple "8511.937935")
+ (math-read-number-simple "-4237922.726")
+ (math-read-number-simple "734926455.1")
+ (math-read-number-simple "-51534381390.0")
+ (math-read-number-simple "1275274390000.0")
+ (math-read-number-simple "-4900604943000.0")))
(math-poly-eval y
- (eval-when-compile
- (list
- '(float 1 0)
- (math-read-number-simple "354.9632885")
- (math-read-number-simple "102042.605")
- (math-read-number-simple "22459040.02")
- (math-read-number-simple "3733650367.0")
- (math-read-number-simple "424441966400.0")
- (math-read-number-simple "24995805700000.0"))))))
- (math-mul (eval-when-compile (math-read-number-simple "0.636619772"))
+ (list
+ '(float 1 0)
+ (math-read-number-simple "354.9632885")
+ (math-read-number-simple "102042.605")
+ (math-read-number-simple "22459040.02")
+ (math-read-number-simple "3733650367.0")
+ (math-read-number-simple "424441966400.0")
+ (math-read-number-simple "24995805700000.0")))))
+ (math-mul (math-read-number-simple "0.636619772")
(math-sub (math-mul (math-besJ1 x) (math-ln-raw x))
(math-div 1 x))))))
((math-negp (calcFunc-re x))
@@ -832,45 +815,45 @@
(calcFunc-euler n '(float 5 -1)))
(calcFunc-euler n '(frac 1 2))))))
-(defvar math-bernoulli-b-cache
- (eval-when-compile
- (list
- (list 'frac
- -174611
- (math-read-number-simple "802857662698291200000"))
- (list 'frac
- 43867
- (math-read-number-simple "5109094217170944000"))
- (list 'frac
- -3617
- (math-read-number-simple "10670622842880000"))
- (list 'frac
- 1
- (math-read-number-simple "74724249600"))
- (list 'frac
- -691
- (math-read-number-simple "1307674368000"))
- (list 'frac
- 1
- (math-read-number-simple "47900160"))
- (list 'frac
- -1
- (math-read-number-simple "1209600"))
- (list 'frac
- 1
- 30240)
- (list 'frac
- -1
- 720)
- (list 'frac
- 1
- 12)
- 1 )))
-
-(defvar math-bernoulli-B-cache '((frac -174611 330) (frac 43867 798)
- (frac -3617 510) (frac 7 6) (frac -691 2730)
- (frac 5 66) (frac -1 30) (frac 1 42)
- (frac -1 30) (frac 1 6) 1 ))
+(defvar math-bernoulli-b-cache
+ (list
+ (list 'frac
+ -174611
+ (math-read-number-simple "802857662698291200000"))
+ (list 'frac
+ 43867
+ (math-read-number-simple "5109094217170944000"))
+ (list 'frac
+ -3617
+ (math-read-number-simple "10670622842880000"))
+ (list 'frac
+ 1
+ (math-read-number-simple "74724249600"))
+ (list 'frac
+ -691
+ (math-read-number-simple "1307674368000"))
+ (list 'frac
+ 1
+ (math-read-number-simple "47900160"))
+ (list 'frac
+ -1
+ (math-read-number-simple "1209600"))
+ (list 'frac
+ 1
+ 30240)
+ (list 'frac
+ -1
+ 720)
+ (list 'frac
+ 1
+ 12)
+ 1 ))
+
+(defvar math-bernoulli-B-cache
+ '((frac -174611 330) (frac 43867 798)
+ (frac -3617 510) (frac 7 6) (frac -691 2730)
+ (frac 5 66) (frac -1 30) (frac 1 42)
+ (frac -1 30) (frac 1 6) 1 ))
(defvar math-bernoulli-cache-size 11)
(defun math-bernoulli-coefs (n)
diff --git a/lisp/calc/calc-math.el b/lisp/calc/calc-math.el
index a4dad15c14e..3e4743d58ae 100644
--- a/lisp/calc/calc-math.el
+++ b/lisp/calc/calc-math.el
@@ -1794,16 +1794,14 @@ If this can't be done, return NIL."
(math-lnp1-series nextsum (1+ n) nextx x))))
(defconst math-approx-ln-10
- (eval-when-compile
- (math-read-number-simple "2.302585092994045684018"))
+ (math-read-number-simple "2.302585092994045684018")
"An approximation for ln(10).")
(math-defcache math-ln-10 math-approx-ln-10
(math-ln-raw-2 '(float 1 1)))
(defconst math-approx-ln-2
- (eval-when-compile
- (math-read-number-simple "0.693147180559945309417"))
+ (math-read-number-simple "0.693147180559945309417")
"An approximation for ln(2).")
(math-defcache math-ln-2 math-approx-ln-2
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index e823a57aef0..3724490169a 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -40,45 +40,47 @@
;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov)
;;; Updated April 2002 by Jochen Küpper
-;;; for CODATA 1998 see one of
-;;; - Journal of Physical and Chemical Reference Data, 28(6), 1713-1852, 1999.
-;;; - Reviews of Modern Physics, 72(2), 351-495, 2000.
-;;; for CODATA 2005 see
-;;; - http://physics.nist.gov/cuu/Constants/index.html
+;;; Updated August 2007, using
+;;; CODATA (http://physics.nist.gov/cuu/Constants/index.html)
+;;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html)
+;;; ESUWM (Encyclopaedia of Scientific Units, Weights and
+;;; Measures, by François Cardarelli)
+;;; All conversions are exact unless otherwise noted.
(defvar math-standard-units
'( ;; Length
( m nil "*Meter" )
- ( in "2.54 cm" "Inch" )
+ ( in "254*10^(-2) cm" "Inch" )
( ft "12 in" "Foot" )
( yd "3 ft" "Yard" )
( mi "5280 ft" "Mile" )
- ( au "149597870691 m" "Astronomical Unit" ) ;; NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html)
- ( lyr "9460536207068016 m" "Light Year" )
- ( pc "206264.80625 au" "Parsec" )
+ ( au "149597870691. m" "Astronomical Unit" )
+ ;; (approx) NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html)
+ ( lyr "c yr" "Light Year" )
+ ( pc "3.0856775854e16 m" "Parsec" ) ;; (approx) ESUWM
( nmi "1852 m" "Nautical Mile" )
( fath "6 ft" "Fathom" )
( mu "1 um" "Micron" )
( mil "in/1000" "Mil" )
( point "in/72" "Point (1/72 inch)" )
- ( Ang "1e-10 m" "Angstrom" )
+ ( Ang "10^(-10) m" "Angstrom" )
( mfi "mi+ft+in" "Miles + feet + inches" )
;; TeX lengths
- ( texpt "in/72.27" "Point (TeX conventions)" )
+ ( texpt "(100/7227) in" "Point (TeX conventions)" )
( texpc "12 texpt" "Pica" )
( texbp "point" "Big point (TeX conventions)" )
- ( texdd "1238/1157 texpt" "Didot point" )
+ ( texdd "(1238/1157) texpt" "Didot point" )
( texcc "12 texdd" "Cicero" )
- ( texsp "1/66536 texpt" "Scaled TeX point" )
+ ( texsp "(1/65536) texpt" "Scaled TeX point" )
;; Area
( hect "10000 m^2" "*Hectare" )
( a "100 m^2" "Are")
( acre "mi^2 / 640" "Acre" )
- ( b "1e-28 m^2" "Barn" )
+ ( b "10^(-28) m^2" "Barn" )
;; Volume
- ( L "1e-3 m^3" "*Liter" )
+ ( L "10^(-3) m^3" "*Liter" )
( l "L" "Liter" )
( gal "4 qt" "US Gallon" )
( qt "2 pt" "Quart" )
@@ -87,10 +89,12 @@
( ozfl "2 tbsp" "Fluid Ounce" )
( floz "2 tbsp" "Fluid Ounce" )
( tbsp "3 tsp" "Tablespoon" )
- ( tsp "4.92892159375 ml" "Teaspoon" )
+ ;; ESUWM defines a US gallon as 231 in^3.
+ ;; That gives the following exact value for tsp.
+ ( tsp "492892159375*10^(-11) ml" "Teaspoon" )
( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" )
- ( galC "4.54609 L" "Canadian Gallon" )
- ( galUK "4.546092 L" "UK Gallon" )
+ ( galC "galUK" "Canadian Gallon" )
+ ( galUK "454609*10^(-5) L" "UK Gallon" ) ;; NIST
;; Time
( s nil "*Second" )
@@ -100,44 +104,44 @@
( day "24 hr" "Day" )
( wk "7 day" "Week" )
( hms "wk+day+hr+min+s" "Hours, minutes, seconds" )
- ( yr "365.25 day" "Year" )
+ ( yr "365.25 day" "Year" ) ;; (approx, but keep)
( Hz "1/s" "Hertz" )
;; Speed
( mph "mi/hr" "*Miles per hour" )
( kph "km/hr" "Kilometers per hour" )
( knot "nmi/hr" "Knot" )
- ( c "299792458 m/s" "Speed of light" ) ;;; CODATA 2005
+ ( c "299792458 m/s" "Speed of light" ) ;;; CODATA
;; Acceleration
- ( ga "9.80665 m/s^2" "*\"g\" acceleration" ) ;; CODATA 2005
+ ( ga "980665*10^(-5) m/s^2" "*\"g\" acceleration" ) ;; CODATA
;; Mass
( g nil "*Gram" )
( lb "16 oz" "Pound (mass)" )
- ( oz "28.349523125 g" "Ounce (mass)" )
+ ( oz "28349523125*10^(-9) g" "Ounce (mass)" ) ;; ESUWM
( ton "2000 lb" "Ton" )
( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
( t "1000 kg" "Metric ton" )
- ( tonUK "1016.0469088 kg" "UK ton" )
+ ( tonUK "10160469088*10^(-7) kg" "UK ton" ) ;; ESUWM
( lbt "12 ozt" "Troy pound" )
- ( ozt "31.103475 g" "Troy ounce" )
- ( ct ".2 g" "Carat" )
- ( u "1.66053886e-27 kg" "Unified atomic mass" ) ;; CODATA 2005
+ ( ozt "31.10347680 g" "Troy ounce" ) ;; (approx) ESUWM
+ ( ct "(2/10) g" "Carat" ) ;; ESUWM
+ ( u "1.660538782e-27 kg" "Unified atomic mass" );;(approx) CODATA
;; Force
( N "m kg/s^2" "*Newton" )
- ( dyn "1e-5 N" "Dyne" )
+ ( dyn "10^(-5) N" "Dyne" )
( gf "ga g" "Gram (force)" )
- ( lbf "4.44822161526 N" "Pound (force)" )
+ ( lbf "ga lb" "Pound (force)" )
( kip "1000 lbf" "Kilopound (force)" )
- ( pdl "0.138255 N" "Poundal" )
+ ( pdl "138254954376*10^(-12) N" "Poundal" ) ;; ESUWM
;; Energy
( J "N m" "*Joule" )
- ( erg "1e-7 J" "Erg" )
- ( cal "4.1868 J" "International Table Calorie" )
- ( Btu "1055.05585262 J" "International Table Btu" )
+ ( erg "10^(-7) J" "Erg" )
+ ( cal "4.18674 J" "International Table Calorie" );;(approx) ESUWM
+ ( Btu "105505585262*10^(-8) J" "International Table Btu" ) ;; ESUWM
( eV "ech V" "Electron volt" )
( ev "eV" "Electron volt" )
( therm "105506000 J" "EEC therm" )
@@ -151,7 +155,7 @@
;; Power
( W "J/s" "*Watt" )
- ( hp "745.7 W" "Horsepower" )
+ ( hp "745.699871581 W" "Horsepower" ) ;;(approx) ESUWM
;; Temperature
( K nil "*Degree Kelvin" K )
@@ -164,24 +168,24 @@
;; Pressure
( Pa "N/m^2" "*Pascal" )
- ( bar "1e5 Pa" "Bar" )
- ( atm "101325 Pa" "Standard atmosphere" ) ;; CODATA 2005
- ( Torr " 1.333224e2 Pa" "Torr" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html)
+ ( bar "10^5 Pa" "Bar" )
+ ( atm "101325 Pa" "Standard atmosphere" ) ;; CODATA
+ ( Torr "1.333224e2 Pa" "Torr" ) ;;(approx) NIST
( mHg "1000 Torr" "Meter of mercury" )
- ( inHg "25.4 mmHg" "Inch of mercury" )
- ( inH2O "2.490889e2 Pa" "Inch of water" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html)
- ( psi "6894.75729317 Pa" "Pound per square inch" )
+ ( inHg "254*10^(-1) mmHg" "Inch of mercury" )
+ ( inH2O "2.490889e2 Pa" "Inch of water" ) ;;(approx) NIST
+ ( psi "lbf/in^2" "Pounds per square inch" )
;; Viscosity
- ( P "0.1 Pa s" "*Poise" )
- ( St "1e-4 m^2/s" "Stokes" )
+ ( P "(1/10) Pa s" "*Poise" )
+ ( St "10^(-4) m^2/s" "Stokes" )
;; Electromagnetism
( A nil "*Ampere" )
( C "A s" "Coulomb" )
( Fdy "ech Nav" "Faraday" )
- ( e "1.60217653e-19 C" "Elementary charge" ) ;; CODATA 2005
- ( ech "1.60217653e-19 C" "Elementary charge" ) ;; CODATA 2005
+ ( e "ech" "Elementary charge" )
+ ( ech "1.602176487e-19 C" "Elementary charge" ) ;;(approx) CODATA
( V "W/A" "Volt" )
( ohm "V/A" "Ohm" )
( mho "A/V" "Mho" )
@@ -189,26 +193,26 @@
( F "C/V" "Farad" )
( H "Wb/A" "Henry" )
( T "Wb/m^2" "Tesla" )
- ( Gs "1e-4 T" "Gauss" )
+ ( Gs "10^(-4) T" "Gauss" )
( Wb "V s" "Weber" )
;; Luminous intensity
( cd nil "*Candela" )
- ( sb "1e4 cd/m^2" "Stilb" )
+ ( sb "10000 cd/m^2" "Stilb" )
( lm "cd sr" "Lumen" )
( lx "lm/m^2" "Lux" )
- ( ph "1e4 lx" "Phot" )
- ( fc "10.76391 lx" "Footcandle" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html)
- ( lam "1e4 lm/m^2" "Lambert" )
- ( flam "3.426259 cd/m^2" "Footlambert" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html)
+ ( ph "10000 lx" "Phot" )
+ ( fc "10.76391 lx" "Footcandle" ) ;;(approx) NIST
+ ( lam "10000 lm/m^2" "Lambert" )
+ ( flam "3.426259 cd/m^2" "Footlambert" ) ;;(approx) NIST
;; Radioactivity
( Bq "1/s" "*Becquerel" )
- ( Ci "3.7e10 Bq" "Curie" )
+ ( Ci "37*10^9 Bq" "Curie" ) ;; ESUWM
( Gy "J/kg" "Gray" )
( Sv "Gy" "Sievert" )
- ( R "2.58e-4 C/kg" "Roentgen" )
- ( rd ".01 Gy" "Rad" )
+ ( R "258*10^(-6) C/kg" "Roentgen" ) ;; NIST
+ ( rd "(1/100) Gy" "Rad" )
( rem "rd" "Rem" )
;; Amount of substance
@@ -228,23 +232,24 @@
( sr nil "*Steradian" )
;; Other physical quantities
- ( h "6.6260693e-34 J s" "*Planck's constant" ) ;; CODATA 2005
- ( hbar "h / 2 pi" "Planck's constant" )
- ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" )
- ( G "6.6742e-11 m^3/kg^1/s^2" "Gravitational constant" ) ;; CODATA 2005
- ( Nav "6.02214115e23 / mol" "Avagadro's constant" ) ;; CODATA 2005
- ( me "9.1093826e-31 kg" "Electron rest mass" ) ;; CODATA 2005
- ( mp "1.67262171e-27 kg" "Proton rest mass" ) ;; CODATA 2005
- ( mn "1.67492728e-27 kg" "Neutron rest mass" ) ;; CODATA 2005
- ( mmu "1.88353140e-28 kg" "Muon rest mass" ) ;; CODATA 2005
- ( Ryd "10973731.568525 /m" "Rydberg's constant" ) ;; CODATA 2005
- ( k "1.3806505e-23 J/K" "Boltzmann's constant" ) ;; CODATA 2005
- ( alpha "7.297352568e-3" "Fine structure constant" ) ;; CODATA 2005
- ( muB "927.400949e-26 J/T" "Bohr magneton" ) ;; CODATA 2005
- ( muN "5.05078343e-27 J/T" "Nuclear magneton" ) ;; CODATA 2005
- ( mue "-928.476412e-26 J/T" "Electron magnetic moment" ) ;; CODATA 2005
- ( mup "1.41060671e-26 J/T" "Proton magnetic moment" ) ;; CODATA 2005
- ( R0 "8.314472 J/mol/K" "Molar gas constant" ) ;; CODATA 2005
+ ;; The values are from CODATA, and are approximate.
+ ( h "6.62606896e-34 J s" "*Planck's constant" )
+ ( hbar "h / (2 pi)" "Planck's constant" )
+ ( mu0 "4 pi 10^(-7) H/m" "Permeability of vacuum" )
+ ( G "6.67428e-11 m^3/(kg s^2)" "Gravitational constant" )
+ ( Nav "6.02214179e23 / mol" "Avagadro's constant" )
+ ( me "9.10938215e-31 kg" "Electron rest mass" )
+ ( mp "1.672621637e-27 kg" "Proton rest mass" )
+ ( mn "1.674927211e-27 kg" "Neutron rest mass" )
+ ( mmu "1.88353130e-28 kg" "Muon rest mass" )
+ ( Ryd "10973731.568527 /m" "Rydberg's constant" )
+ ( k "1.3806504e-23 J/K" "Boltzmann's constant" )
+ ( alpha "7.2973525376e-3" "Fine structure constant" )
+ ( muB "927.400915e-26 J/T" "Bohr magneton" )
+ ( muN "5.05078324e-27 J/T" "Nuclear magneton" )
+ ( mue "-928.476377e-26 J/T" "Electron magnetic moment" )
+ ( mup "1.410606662e-26 J/T" "Proton magnetic moment" )
+ ( R0 "8.314472 J/(mol K)" "Molar gas constant" )
( V0 "22.710981e-3 m^3/mol" "Standard volume of ideal gas" )))
@@ -255,35 +260,35 @@ If this is changed, be sure to set math-units-table to nil to ensure
that the combined units table will be rebuilt.")
(defvar math-unit-prefixes
- '( ( ?Y (float 1 24) "Yotta" )
- ( ?Z (float 1 21) "Zetta" )
- ( ?E (float 1 18) "Exa" )
- ( ?P (float 1 15) "Peta" )
- ( ?T (float 1 12) "Tera" )
- ( ?G (float 1 9) "Giga" )
- ( ?M (float 1 6) "Mega" )
- ( ?k (float 1 3) "Kilo" )
- ( ?K (float 1 3) "Kilo" )
- ( ?h (float 1 2) "Hecto" )
- ( ?H (float 1 2) "Hecto" )
- ( ?D (float 1 1) "Deka" )
- ( 0 (float 1 0) nil )
- ( ?d (float 1 -1) "Deci" )
- ( ?c (float 1 -2) "Centi" )
- ( ?m (float 1 -3) "Milli" )
- ( ?u (float 1 -6) "Micro" )
- ( ?n (float 1 -9) "Nano" )
- ( ?p (float 1 -12) "Pico" )
- ( ?f (float 1 -15) "Femto" )
- ( ?a (float 1 -18) "Atto" )
- ( ?z (float 1 -21) "zepto" )
- ( ?y (float 1 -24) "yocto" )))
+ '( ( ?Y (^ 10 24) "Yotta" )
+ ( ?Z (^ 10 21) "Zetta" )
+ ( ?E (^ 10 18) "Exa" )
+ ( ?P (^ 10 15) "Peta" )
+ ( ?T (^ 10 12) "Tera" )
+ ( ?G (^ 10 9) "Giga" )
+ ( ?M (^ 10 6) "Mega" )
+ ( ?k (^ 10 3) "Kilo" )
+ ( ?K (^ 10 3) "Kilo" )
+ ( ?h (^ 10 2) "Hecto" )
+ ( ?H (^ 10 2) "Hecto" )
+ ( ?D (^ 10 1) "Deka" )
+ ( 0 (^ 10 0) nil )
+ ( ?d (^ 10 -1) "Deci" )
+ ( ?c (^ 10 -2) "Centi" )
+ ( ?m (^ 10 -3) "Milli" )
+ ( ?u (^ 10 -6) "Micro" )
+ ( ?n (^ 10 -9) "Nano" )
+ ( ?p (^ 10 -12) "Pico" )
+ ( ?f (^ 10 -15) "Femto" )
+ ( ?a (^ 10 -18) "Atto" )
+ ( ?z (^ 10 -21) "zepto" )
+ ( ?y (^ 10 -24) "yocto" )))
(defvar math-standard-units-systems
'( ( base nil )
- ( si ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) )
- ( mks ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) )
- ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) )))
+ ( si ( ( g '(/ (var kg var-kg) 1000) ) ) )
+ ( mks ( ( g '(/ (var kg var-kg) 1000) ) ) )
+ ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) )))
(defvar math-units-table nil
"Internal units table derived from math-defined-units.
@@ -321,13 +326,67 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
(math-simplify-units
(math-mul expr (nth pos units))))))))
+(defun math-get-standard-units (expr)
+ "Return the standard units in EXPR."
+ (math-simplify-units
+ (math-extract-units
+ (math-to-standard-units expr nil))))
+
+(defun math-get-units (expr)
+ "Return the units in EXPR."
+ (math-simplify-units
+ (math-extract-units expr)))
+
+(defun math-make-unit-string (expr)
+ "Return EXPR in string form.
+If EXPR is nil, return nil."
+ (if expr
+ (let ((cexpr (math-compose-expr expr 0)))
+ (replace-regexp-in-string
+ " / " "/"
+ (if (stringp cexpr)
+ cexpr
+ (math-composition-to-string cexpr))))))
+
+(defvar math-default-units-table
+ (make-hash-table :test 'equal)
+ "A table storing previously converted units.")
+
+(defun math-get-default-units (expr)
+ "Get default units to use when converting the units in EXPR."
+ (let* ((units (math-get-units expr))
+ (standard-units (math-get-standard-units expr))
+ (default-units (gethash
+ standard-units
+ math-default-units-table)))
+ (if (equal units (car default-units))
+ (math-make-unit-string (cadr default-units))
+ (math-make-unit-string (car default-units)))))
+
+(defun math-put-default-units (expr)
+ "Put the units in EXPR in the default units table."
+ (let* ((units (math-get-units expr))
+ (standard-units (math-get-standard-units expr))
+ (default-units (gethash
+ standard-units
+ math-default-units-table)))
+ (cond
+ ((not default-units)
+ (puthash standard-units (list units) math-default-units-table))
+ ((not (equal units (car default-units)))
+ (puthash standard-units
+ (list units (car default-units))
+ math-default-units-table)))))
+
+
(defun calc-convert-units (&optional old-units new-units)
(interactive)
(calc-slow-wrapper
(let ((expr (calc-top-n 1))
(uoldname nil)
unew
- units)
+ units
+ defunits)
(unless (math-units-in-expr-p expr t)
(let ((uold (or old-units
(progn
@@ -343,16 +402,31 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
(error "Bad format in units expression: %s" (nth 1 uold)))
(setq expr (math-mul expr uold))))
(unless new-units
- (setq new-units (read-string (if uoldname
- (concat "Old units: "
- uoldname
- ", new units: ")
- "New units: "))))
+ (setq defunits (math-get-default-units expr))
+ (setq new-units
+ (read-string (concat
+ (if uoldname
+ (concat "Old units: "
+ uoldname
+ ", new units")
+ "New units")
+ (if defunits
+ (concat
+ " (default: "
+ defunits
+ "): ")
+ ": "))))
+
+ (if (and
+ (string= new-units "")
+ defunits)
+ (setq new-units defunits)))
(when (string-match "\\` */" new-units)
(setq new-units (concat "1" new-units)))
(setq units (math-read-expr new-units))
(when (eq (car-safe units) 'error)
(error "Bad format in units expression: %s" (nth 2 units)))
+ (math-put-default-units units)
(let ((unew (math-units-in-expr-p units t))
(std (and (eq (car-safe units) 'var)
(assq (nth 1 units) math-standard-units-systems))))
@@ -381,7 +455,8 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
(let ((expr (calc-top-n 1))
(uold nil)
(uoldname nil)
- unew)
+ unew
+ defunits)
(setq uold (or old-units
(let ((units (math-single-units-in-expr-p expr)))
(if units
@@ -398,15 +473,24 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
(error "Bad format in units expression: %s" (nth 2 uold)))
(or (math-units-in-expr-p expr nil)
(setq expr (math-mul expr uold)))
+ (setq defunits (math-get-default-units expr))
(setq unew (or new-units
(math-read-expr
- (read-string (if uoldname
- (concat "Old temperature units: "
- uoldname
- ", new units: ")
- "New temperature units: ")))))
+ (read-string
+ (concat
+ (if uoldname
+ (concat "Old temperature units: "
+ uoldname
+ ", new units")
+ "New temperature units")
+ (if defunits
+ (concat " (default: "
+ defunits
+ "): ")
+ ": "))))))
(when (eq (car-safe unew) 'error)
(error "Bad format in units expression: %s" (nth 2 unew)))
+ (math-put-default-units unew)
(calc-enter-result 1 "cvtm" (math-simplify-units
(math-convert-temperature expr uold unew
uoldname))))))
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index 755834f913c..8e416293a45 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -229,7 +229,8 @@
(c-mode . c)
(c++-mode . c)
(fortran-mode . fortran)
- (f90-mode . fortran))
+ (f90-mode . fortran)
+ (texinfo-mode . calc-normal-language))
"*Alist of major modes with appropriate Calc languages."
:group 'calc
:type '(alist :key-type (symbol :tag "Major mode")
@@ -2283,8 +2284,8 @@ See calc-keypad for details."
-(defconst math-bignum-digit-length 4
-; (truncate (/ (log10 (/ most-positive-fixnum 2)) 2))
+(defconst math-bignum-digit-length
+ (truncate (/ (log10 (/ most-positive-fixnum 2)) 2))
"The length of a \"digit\" in Calc bignums.
If a big integer is of the form (bigpos N0 N1 ...), this is the
length of the allowable Emacs integers N0, N1,...