Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / calc / calc-units.el
index 27d76fe..2f650fc 100644 (file)
@@ -1,17 +1,17 @@
 ;;; calc-units.el --- unit conversion functions for Calc
 
 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 (defvar math-standard-units
   '( ;; Length
     ( m       nil                    "*Meter" )
-    ( in      "254*10^(-2) cm"       "Inch" )
-    ( ft      "12 in"                "Foot" )
+    ( in      "254*10^(-2) cm"       "Inch"  nil
+              "2.54 cm")
+    ( ft      "12 in"                "Foot")
     ( yd      "3 ft"                 "Yard" )
     ( mi      "5280 ft"              "Mile" )
-    ( au      "149597870691. m"      "Astronomical Unit" )
+    ( au      "149597870691. m"      "Astronomical Unit" nil
+              "149597870691 m (*)")
               ;; (approx) NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html)
     ( lyr     "c yr"                 "Light Year" )
-    ( pc      "3.0856775854e16 m"    "Parsec" ) ;; (approx) ESUWM
+    ( pc      "3.0856775854*10^16 m" "Parsec" nil
+              "3.0856775854 10^16 m (*)") ;; (approx) ESUWM
     ( nmi     "1852 m"               "Nautical Mile" )
     ( fath    "6 ft"                 "Fathom" )
+    ( fur     "660 ft"               "Furlong")
     ( mu      "1 um"                 "Micron" )
-    ( mil     "in/1000"              "Mil" )
-    ( point   "in/72"                "Point (1/72 inch)" )
+    ( mil     "(1/1000) in"          "Mil" )
+    ( point   "(1/72) in"            "Point (1/72 inch)" )
     ( Ang     "10^(-10) m"           "Angstrom" )
     ( mfi     "mi+ft+in"             "Miles + feet + inches" )
     ;; TeX lengths
@@ -76,7 +78,7 @@
     ;; Area
     ( hect    "10000 m^2"            "*Hectare" )
     ( a       "100 m^2"              "Are")
-    ( acre    "mi^2 / 640"           "Acre" )
+    ( acre    "(1/640) mi^2"         "Acre" )
     ( b       "10^(-28) m^2"         "Barn" )
 
     ;; Volume
     ( tbsp    "3 tsp"                "Tablespoon" )
     ;; 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" )
+    ( tsp     "492892159375*10^(-11) ml" "Teaspoon" nil
+              "4.92892159375 ml")
+    ( vol     "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" nil
+              "tsp+tbsp+ozfl+cup+pt+qt+gal")
     ( galC    "galUK"                "Canadian Gallon" )
-    ( galUK   "454609*10^(-5) L"     "UK Gallon" ) ;; NIST
+    ( galUK   "454609*10^(-5) L"     "UK Gallon" nil
+              "4.54609 L") ;; NIST
 
     ;; Time
     ( s       nil                    "*Second" )
     ( day     "24 hr"                "Day" )
     ( wk      "7 day"                "Week" )
     ( hms     "wk+day+hr+min+s"      "Hours, minutes, seconds" )
-    ( yr      "365.25 day"           "Year" ) ;; (approx, but keep)
+    ( yr      "36525*10^(-2) day"    "Year (Julian)" nil
+              "365.25 day")
     ( Hz      "1/s"                  "Hertz" )
 
     ;; Speed
     ( c       "299792458 m/s"        "Speed of light" ) ;;; CODATA
 
     ;; Acceleration
-    ( ga      "980665*10^(-5) m/s^2" "*\"g\" acceleration" ) ;; CODATA
+    ( ga      "980665*10^(-5) m/s^2" "*\"g\" acceleration" nil
+              "9.80665 m / s^2") ;; CODATA
 
     ;; Mass
     ( g       nil                    "*Gram" )
     ( lb      "16 oz"                "Pound (mass)" )
-    ( oz      "28349523125*10^(-9) g" "Ounce (mass)" ) ;; ESUWM
+    ( oz      "28349523125*10^(-9) g" "Ounce (mass)" nil
+              "28.349523125 g") ;; ESUWM
     ( ton     "2000 lb"              "Ton" )
     ( tpo     "ton+lb+oz"            "Tons + pounds + ounces (mass)" )
     ( t       "1000 kg"              "Metric ton" )
-    ( tonUK   "10160469088*10^(-7) kg" "UK ton" ) ;; ESUWM
+    ( tonUK   "10160469088*10^(-7) kg" "UK ton" nil
+              "1016.0469088 kg") ;; ESUWM
     ( lbt     "12 ozt"               "Troy pound" )
-    ( ozt     "31.10347680 g"        "Troy ounce" ) ;; (approx) ESUWM
-    ( ct      "(2/10) g"             "Carat" ) ;; ESUWM
-    ( u       "1.660538782e-27 kg"    "Unified atomic mass" );;(approx) CODATA
+    ( ozt     "311034768*10^(-7) g"        "Troy ounce" nil
+              "31.10347680 g") ;; ESUWM, 1/12 exact value for lbt
+    ( ct      "(2/10) g"             "Carat" nil
+              "0.2 g") ;; ESUWM
+    ( u       "1.660538782*10^(-27) kg"    "Unified atomic mass" nil
+              "1.660538782 10^-27 kg (*)");;(approx) CODATA
 
     ;; Force
     ( N       "m kg/s^2"             "*Newton" )
     ( gf      "ga g"                 "Gram (force)" )
     ( lbf     "ga lb"                "Pound (force)" )
     ( kip     "1000 lbf"             "Kilopound (force)" )
-    ( pdl     "138254954376*10^(-12) N" "Poundal" ) ;; ESUWM
+    ( pdl     "138254954376*10^(-12) N" "Poundal" nil
+              "0.138254954376 N") ;; ESUWM
 
     ;; Energy
     ( J       "N m"                  "*Joule" )
     ( erg     "10^(-7) J"            "Erg" )
-    ( cal     "4.18674 J"            "International Table Calorie" );;(approx) ESUWM
-    ( Btu     "105505585262*10^(-8) J" "International Table Btu" ) ;; ESUWM
+    ( cal     "41868*10^(-4) J"      "International Table Calorie" nil
+              "4.1868 J") ;; NIST
+    ( calth   "4184*10^(-3) J"       "Thermochemical Calorie" nil
+              "4.184 J") ;; NIST
+    ( Cal     "1000 cal"             "Large Calorie")
+    ( Btu     "105505585262*10^(-8) J" "International Table Btu" nil
+              "1055.05585262 J") ;; ESUWM
     ( eV      "ech V"                "Electron volt" )
     ( ev      "eV"                   "Electron volt" )
     ( therm   "105506000 J"          "EEC therm" )
 
     ;; Power
     ( W       "J/s"                  "*Watt" )
-    ( hp      "745.699871581 W"      "Horsepower" ) ;;(approx) ESUWM
+    ( hp      "550 ft lbf/s"         "Horsepower") ;;ESUWM
+    ( hpm     "75 m kgf/s"           "Metric Horsepower") ;;ESUWM
 
     ;; Temperature
     ( K       nil                    "*Degree Kelvin"     K )
     ( Pa      "N/m^2"                "*Pascal" )
     ( bar     "10^5 Pa"              "Bar" )
     ( atm     "101325 Pa"            "Standard atmosphere" ) ;; CODATA
-    ( Torr    "1.333224e2 Pa"        "Torr" ) ;;(approx) NIST
+    ( Torr    "(1/760) atm"          "Torr")
     ( mHg     "1000 Torr"            "Meter of mercury" )
-    ( inHg    "254*10^(-1) mmHg"     "Inch of mercury" )
-    ( inH2O   "2.490889e2 Pa"        "Inch of water" ) ;;(approx) NIST
+    ( inHg    "254*10^(-1) mmHg"     "Inch of mercury" nil
+              "25.4 mmHg")
+    ( inH2O   "2.490889*10^2 Pa"        "Inch of water" nil
+              "2.490889 10^2 Pa (*)") ;;(approx) NIST
     ( psi     "lbf/in^2"             "Pounds per square inch" )
 
     ;; Viscosity
     ( C       "A s"                   "Coulomb" )
     ( Fdy     "ech Nav"               "Faraday" )
     ( e       "ech"                   "Elementary charge" )
-    ( ech     "1.602176487e-19 C"     "Elementary charge" ) ;;(approx) CODATA
+    ( ech     "1.602176487*10^(-19) C"     "Elementary charge" nil
+              "1.602176487 10^-19 C (*)") ;;(approx) CODATA
     ( V       "W/A"                   "Volt" )
     ( ohm     "V/A"                   "Ohm" )
     ( mho     "A/V"                   "Mho" )
     ( lm      "cd sr"                 "Lumen" )
     ( lx      "lm/m^2"                "Lux" )
     ( ph      "10000 lx"              "Phot" )
-    ( fc      "10.76391 lx"           "Footcandle" ) ;;(approx) NIST
+    ( fc      "lm/ft^2"               "Footcandle") ;; ESUWM
     ( lam     "10000 lm/m^2"          "Lambert" )
-    ( flam    "3.426259 cd/m^2"       "Footlambert" ) ;;(approx) NIST
+    ( flam    "(1/pi) cd/ft^2"        "Footlambert") ;; ESUWM
 
     ;; Radioactivity
     ( Bq      "1/s"                    "*Becquerel" )
 
     ;; Other physical quantities
     ;; 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" )))
+    ( h       "6.62606896*10^(-34) J s"     "*Planck's constant" nil
+              "6.62606896 10^-34 J s (*)")
+    ( hbar    "h / (2 pi)"                  "Planck's constant" ) ;; Exact
+    ( mu0     "4 pi 10^(-7) H/m"            "Permeability of vacuum") ;; Exact
+    ( eps0    "1 / (mu0 c^2)"               "Permittivity of vacuum" )
+    ( G       "6.67428*10^(-11) m^3/(kg s^2)"    "Gravitational constant" nil
+              "6.67428 10^-11 m^3/(kg s^2) (*)")
+    ( Nav     "6.02214179*10^(23) / mol"    "Avogadro's constant" nil
+              "6.02214179 10^23 / mol (*)")
+    ( me      "9.10938215*10^(-31) kg"      "Electron rest mass" nil
+              "9.10938215 10^-31 kg (*)")
+    ( mp      "1.672621637*10^(-27) kg"     "Proton rest mass" nil
+              "1.672621637 10^-27 kg (*)")
+    ( mn      "1.674927211*10^(-27) kg"     "Neutron rest mass" nil
+              "1.674927211 10^-27 kg (*)")
+    ( mmu     "1.88353130*10^(-28) kg"      "Muon rest mass" nil
+              "1.88353130 10^-28 kg (*)")
+    ( Ryd     "10973731.568527 /m"          "Rydberg's constant" nil
+              "10973731.568527 /m (*)")
+    ( k       "1.3806504*10^(-23) J/K"      "Boltzmann's constant" nil
+              "1.3806504 10^-23 J/K (*)")
+    ( alpha   "7.2973525376*10^(-3)"        "Fine structure constant" nil
+              "7.2973525376 10^-3 (*)")
+    ( muB     "927.400915*10^(-26) J/T"     "Bohr magneton" nil
+              "927.400915 10^-26 J/T (*)")
+    ( muN     "5.05078324*10^(-27) J/T"     "Nuclear magneton" nil
+              "5.05078324 10^-27 J/T (*)")
+    ( mue     "-928.476377*10^(-26) J/T"    "Electron magnetic moment" nil
+              "-928.476377 10^-26 J/T (*)")
+    ( mup     "1.410606662*10^(-26) J/T"    "Proton magnetic moment" nil
+              "1.410606662 10^-26 J/T (*)")
+    ( R0      "8.314472 J/(mol K)"          "Molar gas constant" nil
+              "8.314472 J/(mol K) (*)")
+    ( V0      "22.710981*10^(-3) m^3/mol"   "Standard volume of ideal gas" nil
+              "22.710981 10^-3 m^3/mol (*)")))
 
 
 (defvar math-additional-units nil
   "*Additional units table for user-defined units.
-Must be formatted like math-standard-units.
-If this is changed, be sure to set math-units-table to nil to ensure
+Must be formatted like `math-standard-units'.
+If you change this, be sure to set `math-units-table' to nil to ensure
 that the combined units table will be rebuilt.")
 
 (defvar math-unit-prefixes
@@ -291,7 +330,8 @@ that the combined units table will be rebuilt.")
      ( cgs   ( ( m   '(* (var cm var-cm) 100 ) ) ) )))
 
 (defvar math-units-table nil
-  "Internal units table derived from math-defined-units.
+  "Internal units table.
+Derived from `math-standard-units' and `math-additional-units'.
 Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
 
 (defvar math-units-table-buffer-valid nil)
@@ -309,7 +349,7 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
 (defun calc-quick-units ()
   (interactive)
   (calc-slow-wrapper
-   (let* ((num (- last-command-char ?0))
+   (let* ((num (- last-command-event ?0))
          (pos (if (= num 0) 10 num))
          (units (calc-var-value 'var-Units))
          (expr (calc-top-n 1)))
@@ -475,19 +515,19 @@ If EXPR is nil, return nil."
         (setq expr (math-mul expr uold)))
      (setq defunits (math-get-default-units expr))
      (setq unew (or new-units
-                   (math-read-expr
-                    (read-string
-                      (concat
-                       (if uoldname
-                           (concat "Old temperature units: "
-                                   uoldname
-                                   ", new units")
-                         "New temperature units")
-                       (if defunits
-                           (concat " (default "
-                                   defunits
-                                   "): ")
-                         ": "))))))
+                    (read-string
+                     (concat
+                      (if uoldname
+                          (concat "Old temperature units: "
+                                  uoldname
+                                  ", new units")
+                        "New temperature units")
+                      (if defunits
+                          (concat " (default "
+                                  defunits
+                                  "): ")
+                        ": ")))))
+     (setq unew (math-read-expr (if (string= unew "") defunits unew)))
      (when (eq (car-safe unew) 'error)
        (error "Bad format in units expression: %s" (nth 2 unew)))
      (math-put-default-units unew)
@@ -618,14 +658,15 @@ If EXPR is nil, return nil."
   (math-build-units-table-buffer t)
   (message "%s" (substitute-command-keys "Type \\[calc] to return to the Calculator")))
 
-(defun calc-define-unit (uname desc)
-  (interactive "SDefine unit name: \nsDescription: ")
+(defun calc-define-unit (uname desc &optional disp)
+  (interactive "SDefine unit name: \nsDescription: \nP")
+  (if disp (setq disp (read-string "Display definition: ")))
   (calc-wrapper
    (let ((form (calc-top-n 1))
         (unit (assq uname math-additional-units)))
      (or unit
         (setq math-additional-units
-              (cons (setq unit (list uname nil nil))
+              (cons (setq unit (list uname nil nil nil nil))
                     math-additional-units)
               math-units-table nil))
      (setcar (cdr unit) (and (not (and (eq (car-safe form) 'var)
@@ -633,7 +674,9 @@ If EXPR is nil, return nil."
                             (not (math-equal-int form 1))
                             (math-format-flat-expr form 0)))
      (setcar (cdr (cdr unit)) (and (not (equal desc ""))
-                                  desc))))
+                                  desc))
+     (if disp
+         (setcar (cdr (cdr (cdr (cdr unit)))) disp))))
   (calc-invalidate-units-table))
 
 (defun calc-undefine-unit (uname)
@@ -652,8 +695,7 @@ If EXPR is nil, return nil."
   (setq math-units-table nil)
   (let ((buf (get-buffer "*Units Table*")))
     (and buf
-        (save-excursion
-          (set-buffer buf)
+        (with-current-buffer buf
           (save-excursion
             (goto-char (point-min))
             (if (looking-at "Calculator Units Table")
@@ -754,7 +796,8 @@ If EXPR is nil, return nil."
                                   (nth 2 x)
                                   (nth 3 x)
                                   (and (not (nth 1 x))
-                                       (list (cons (car x) 1))))))
+                                       (list (cons (car x) 1)))
+                                   (nth 4 x))))
                          combined-units))
        (let ((math-units-table tab))
          (mapc 'math-find-base-units tab))
@@ -1413,6 +1456,7 @@ If EXPR is nil, return nil."
            (calc-float-format '(float 0))
            (calc-group-digits nil)
            (calc-number-radix 10)
+            (calc-twos-complement-mode nil)
            (calc-point-char ".")
            (std nil)
            u name shadowed)
@@ -1422,6 +1466,7 @@ If EXPR is nil, return nil."
           (let ((inhibit-read-only t))
             (erase-buffer)
             (insert "Calculator Units Table:\n\n")
+            (insert "(All definitions are exact unless marked with an asterisk (*).)\n\n")
             (insert "Unit    Type  Definition                  Description\n\n")
             (while uptr
               (setq u (car uptr)
@@ -1449,9 +1494,11 @@ If EXPR is nil, return nil."
                       (insert "U"))))
               (indent-to 14)
               (and shadowed (insert "("))
-              (if (nth 1 u)
-                  (insert (math-format-value (nth 1 u) 80))
-                (insert (symbol-name (car u))))
+              (if (nth 5 u)
+                  (insert (nth 5 u))
+                (if (nth 1 u)
+                    (insert (math-format-value (nth 1 u) 80))
+                  (insert (symbol-name (car u)))))
               (and shadowed (insert ")"))
               (indent-to 41)
               (insert " ")
@@ -1497,5 +1544,5 @@ If EXPR is nil, return nil."
 ;; coding: iso-latin-1
 ;; End:
 
-;;; arch-tag: e993314f-3adc-4191-be61-4ef8874881c4
+;; arch-tag: e993314f-3adc-4191-be61-4ef8874881c4
 ;;; calc-units.el ends here