-;; Calculator for GNU Emacs, part II [calc-units.el]
+;;; calc-units.el --- unit conversion functions for Calc
+
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs.
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
+;;; Commentary:
+;;; Code:
;; This file is autoloaded from calc-ext.el.
(require 'calc-ext)
(defun calc-Need-calc-units () nil)
+;;; Units operations.
+
+;;; Units table last updated 9-Jan-91 by Ulrich Mueller (ulm@vsnhd1.cern.ch)
+;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov)
+
+(defvar math-standard-units
+ '( ;; Length
+ ( m nil "*Meter" )
+ ( in "2.54 cm" "Inch" )
+ ( ft "12 in" "Foot" )
+ ( yd "3 ft" "Yard" )
+ ( mi "5280 ft" "Mile" )
+ ( au "1.495979e11 m" "Astronomical Unit" )
+ ( lyr "9460536207068016 m" "Light Year" )
+ ( pc "206264.80625 au" "Parsec" )
+ ( nmi "1852 m" "Nautical Mile" )
+ ( fath "6 ft" "Fathom" )
+ ( u "1 um" "Micron" )
+ ( mil "in/1000" "Mil" )
+ ( point "in/72" "Point (1/72 inch)" )
+ ( tpt "in/72.27" "Point (TeX conventions)" )
+ ( Ang "1e-10 m" "Angstrom" )
+ ( mfi "mi+ft+in" "Miles + feet + inches" )
+
+ ;; Area
+ ( hect "10000 m^2" "*Hectare" )
+ ( acre "mi^2 / 640" "Acre" )
+ ( b "1e-28 m^2" "Barn" )
+
+ ;; Volume
+ ( l "1e-3 m^3" "*Liter" )
+ ( L "1e-3 m^3" "Liter" )
+ ( gal "4 qt" "US Gallon" )
+ ( qt "2 pt" "Quart" )
+ ( pt "2 cup" "Pint" )
+ ( cup "8 ozfl" "Cup" )
+ ( ozfl "2 tbsp" "Fluid Ounce" )
+ ( floz "2 tbsp" "Fluid Ounce" )
+ ( tbsp "3 tsp" "Tablespoon" )
+ ( tsp "4.92892159375 ml" "Teaspoon" )
+ ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" )
+ ( galC "4.54609 l" "Canadian Gallon" )
+ ( galUK "4.546092 l" "UK Gallon" )
+
+ ;; Time
+ ( s nil "*Second" )
+ ( sec "s" "Second" )
+ ( min "60 s" "Minute" )
+ ( hr "60 min" "Hour" )
+ ( day "24 hr" "Day" )
+ ( wk "7 day" "Week" )
+ ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" )
+ ( yr "365.25 day" "Year" )
+ ( Hz "1/s" "Hertz" )
+
+ ;; Speed
+ ( mph "mi/hr" "*Miles per hour" )
+ ( kph "km/hr" "Kilometers per hour" )
+ ( knot "nmi/hr" "Knot" )
+ ( c "2.99792458e8 m/s" "Speed of light" )
+
+ ;; Acceleration
+ ( ga "9.80665 m/s^2" "*\"g\" acceleration" )
+
+ ;; Mass
+ ( g nil "*Gram" )
+ ( lb "16 oz" "Pound (mass)" )
+ ( oz "28.349523125 g" "Ounce (mass)" )
+ ( ton "2000 lb" "Ton" )
+ ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
+ ( t "1000 kg" "Metric ton" )
+ ( tonUK "1016.0469088 kg" "UK ton" )
+ ( lbt "12 ozt" "Troy pound" )
+ ( ozt "31.103475 g" "Troy ounce" )
+ ( ct ".2 g" "Carat" )
+ ( amu "1.6605402e-24 g" "Unified atomic mass" )
+
+ ;; Force
+ ( N "m kg/s^2" "*Newton" )
+ ( dyn "1e-5 N" "Dyne" )
+ ( gf "ga g" "Gram (force)" )
+ ( lbf "4.44822161526 N" "Pound (force)" )
+ ( kip "1000 lbf" "Kilopound (force)" )
+ ( pdl "0.138255 N" "Poundal" )
+
+ ;; Energy
+ ( J "N m" "*Joule" )
+ ( erg "1e-7 J" "Erg" )
+ ( cal "4.1868 J" "International Table Calorie" )
+ ( Btu "1055.05585262 J" "International Table Btu" )
+ ( eV "ech V" "Electron volt" )
+ ( ev "eV" "Electron volt" )
+ ( therm "105506000 J" "EEC therm" )
+ ( invcm "h c/cm" "Energy in inverse centimeters" )
+ ( Kayser "invcm" "Kayser (inverse centimeter energy)" )
+ ( men "100/invcm" "Inverse energy in meters" )
+ ( Hzen "h Hz" "Energy in Hertz")
+ ( Ken "k K" "Energy in Kelvins")
+ ;; ( invcm "eV / 8065.47835185" "Energy in inverse centimeters" )
+ ;; ( Hzen "eV / 2.41796958004e14" "Energy in Hertz")
+ ;; ( Ken "eV / 11604.7967327" "Energy in Kelvins")
+
+ ;; Power
+ ( W "J/s" "*Watt" )
+ ( hp "745.7 W" "Horsepower" )
+
+ ;; Temperature
+ ( K nil "*Degree Kelvin" K )
+ ( dK "K" "Degree Kelvin" K )
+ ( degK "K" "Degree Kelvin" K )
+ ( dC "K" "Degree Celsius" C )
+ ( degC "K" "Degree Celsius" C )
+ ( dF "(5/9) K" "Degree Fahrenheit" F )
+ ( degF "(5/9) K" "Degree Fahrenheit" F )
+
+ ;; Pressure
+ ( Pa "N/m^2" "*Pascal" )
+ ( bar "1e5 Pa" "Bar" )
+ ( atm "101325 Pa" "Standard atmosphere" )
+ ( torr "atm/760" "Torr" )
+ ( mHg "1000 torr" "Meter of mercury" )
+ ( inHg "25.4 mmHg" "Inch of mercury" )
+ ( inH2O "248.84 Pa" "Inch of water" )
+ ( psi "6894.75729317 Pa" "Pound per square inch" )
+
+ ;; Viscosity
+ ( P "0.1 Pa s" "*Poise" )
+ ( St "1e-4 m^2/s" "Stokes" )
+
+ ;; Electromagnetism
+ ( A nil "*Ampere" )
+ ( C "A s" "Coulomb" )
+ ( Fdy "ech Nav" "Faraday" )
+ ( e "1.60217733e-19 C" "Elementary charge" )
+ ( ech "1.60217733e-19 C" "Elementary charge" )
+ ( V "W/A" "Volt" )
+ ( ohm "V/A" "Ohm" )
+ ( mho "A/V" "Mho" )
+ ( S "A/V" "Siemens" )
+ ( F "C/V" "Farad" )
+ ( H "Wb/A" "Henry" )
+ ( T "Wb/m^2" "Tesla" )
+ ( G "1e-4 T" "Gauss" )
+ ( Wb "V s" "Weber" )
+
+ ;; Luminous intensity
+ ( cd nil "*Candela" )
+ ( sb "1e4 cd/m^2" "Stilb" )
+ ( lm "cd sr" "Lumen" )
+ ( lx "lm/m^2" "Lux" )
+ ( ph "1e4 lx" "Phot" )
+ ( fc "10.76 lx" "Footcandle" )
+ ( lam "1e4 lm/m^2" "Lambert" )
+ ( flam "1.07639104e-3 lam" "Footlambert" )
+
+ ;; Radioactivity
+ ( Bq "1/s" "*Becquerel" )
+ ( Ci "3.7e10 Bq" "Curie" )
+ ( Gy "J/kg" "Gray" )
+ ( Sv "Gy" "Sievert" )
+ ( R "2.58e-4 C/kg" "Roentgen" )
+ ( rd ".01 Gy" "Rad" )
+ ( rem "rd" "Rem" )
+
+ ;; Amount of substance
+ ( mol nil "*Mole" )
+
+ ;; Plane angle
+ ( rad nil "*Radian" )
+ ( circ "2 pi rad" "Full circle" )
+ ( rev "circ" "Full revolution" )
+ ( deg "circ/360" "Degree" )
+ ( arcmin "deg/60" "Arc minute" )
+ ( arcsec "arcmin/60" "Arc second" )
+ ( grad "circ/400" "Grade" )
+ ( rpm "rev/min" "Revolutions per minute" )
+
+ ;; Solid angle
+ ( sr nil "*Steradian" )
+
+ ;; Other physical quantities (Physics Letters B239, 1 (1990))
+ ( h "6.6260755e-34 J s" "*Planck's constant" )
+ ( hbar "h / 2 pi" "Planck's constant" )
+ ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" )
+ ( Grav "6.67259e-11 N m^2/kg^2" "Gravitational constant" )
+ ( Nav "6.0221367e23 / mol" "Avagadro's constant" )
+ ( me "0.51099906 MeV/c^2" "Electron rest mass" )
+ ( mp "1.007276470 amu" "Proton rest mass" )
+ ( mn "1.008664904 amu" "Neutron rest mass" )
+ ( mu "0.113428913 amu" "Muon rest mass" )
+ ( Ryd "1.0973731571e5 invcm" "Rydberg's constant" )
+ ( k "1.3806513e-23 J/K" "Boltzmann's constant" )
+ ( fsc "1 / 137.0359895" "Fine structure constant" )
+ ( muB "5.78838263e-11 MeV/T" "Bohr magneton" )
+ ( muN "3.15245166e-14 MeV/T" "Nuclear magneton" )
+ ( mue "1.001159652193 muB" "Electron magnetic moment" )
+ ( mup "2.792847386 muN" "Proton magnetic moment" )
+ ( R0 "Nav k" "Molar gas constant" )
+ ( V0 "22.413992 L/mol" "Standard volume of ideal gas" )))
+
+
+(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
+that the combined units table will be rebuilt.")
+
+(defvar math-unit-prefixes
+ '( ( ?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" )))
+
+(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 ) ) ) )))
+
+(defvar math-units-table nil
+ "Internal units table derived from math-defined-units.
+Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
+
+(defvar math-units-table-buffer-valid nil)
;;; Units commands.
(pos (if (= num 0) 10 num))
(units (calc-var-value 'var-Units))
(expr (calc-top-n 1)))
- (or (and (>= num 0) (<= num 9))
- (error "Bad unit number"))
- (or (math-vectorp units)
- (error "No \"quick units\" are defined"))
- (or (< pos (length units))
- (error "Unit number %d not defined" pos))
+ (unless (and (>= num 0) (<= num 9))
+ (errunless "Bad unit number"))
+ (unless (math-vectorp units)
+ (errunless "No \"quick units\" are defined"))
+ (unless (< pos (length units))
+ (errunless "Unit number %d not defined" pos))
(if (math-units-in-expr-p expr nil)
(calc-enter-result 1 (format "cun%d" num)
(math-convert-units expr (nth pos units)))
(let ((expr (calc-top-n 1))
(uoldname nil)
unew)
- (or (math-units-in-expr-p expr t)
- (let ((uold (or old-units
- (progn
- (setq uoldname (read-string "Old units: "))
- (if (equal uoldname "")
- (progn
- (setq uoldname "1")
- 1)
- (if (string-match "\\` */" uoldname)
- (setq uoldname (concat "1" uoldname)))
- (math-read-expr uoldname))))))
- (if (eq (car-safe uold) 'error)
- (error "Bad format in units expression: %s" (nth 1 uold)))
- (setq expr (math-mul expr uold))))
- (or new-units
- (setq new-units (read-string (if uoldname
- (concat "Old units: "
- uoldname
- ", new units: ")
- "New units: "))))
- (if (string-match "\\` */" new-units)
- (setq new-units (concat "1" new-units)))
+ (unless (math-units-in-expr-p expr t)
+ (let ((uold (or old-units
+ (progn
+ (setq uoldname (read-string "Old units: "))
+ (if (equal uoldname "")
+ (progn
+ (setq uoldname "1")
+ 1)
+ (if (string-match "\\` */" uoldname)
+ (setq uoldname (concat "1" uoldname)))
+ (math-read-expr uoldname))))))
+ (when (eq (car-safe uold) 'error)
+ (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: "))))
+ (when (string-match "\\` */" new-units)
+ (setq new-units (concat "1" new-units)))
(setq units (math-read-expr new-units))
- (if (eq (car-safe units) 'error)
- (error "Bad format in units expression: %s" (nth 2 units)))
+ (when (eq (car-safe units) 'error)
+ (error "Bad format in units expression: %s" (nth 2 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))))
(calc-enter-result 1 "cvun" (math-simplify-units
(math-to-standard-units expr
(nth 1 std))))
- (or unew
- (error "No units specified"))
+ (unless unew
+ (error "No units specified"))
(calc-enter-result 1 "cvun"
(math-convert-units
expr units
(calc-wrapper
(calc-change-mode 'calc-autorange-units arg nil t)
(message (if calc-autorange-units
- "Adjusting target unit prefix automatically."
- "Using target units exactly."))))
+ "Adjusting target unit prefix automatically"
+ "Using target units exactly"))))
(defun calc-convert-temperature (&optional old-units new-units)
(interactive)
(math-read-expr
(setq uoldname (read-string
"Old temperature units: ")))))))
- (if (eq (car-safe uold) 'error)
- (error "Bad format in units expression: %s" (nth 2 uold)))
+ (when (eq (car-safe uold) 'error)
+ (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 unew (or new-units
uoldname
", new units: ")
"New temperature units: ")))))
- (if (eq (car-safe unew) 'error)
- (error "Bad format in units expression: %s" (nth 2 unew)))
+ (when (eq (car-safe unew) 'error)
+ (error "Bad format in units expression: %s" (nth 2 unew)))
(calc-enter-result 1 "cvtm" (math-simplify-units
(math-convert-temperature expr uold unew
uoldname))))))
(interactive "P")
(and n (setq math-units-table-buffer-valid nil))
(math-build-units-table-buffer t)
- (message (substitute-command-keys "Type \\[calc] to return to the Calculator.")))
+ (message (substitute-command-keys "Type \\[calc] to return to the Calculator")))
(defun calc-define-unit (uname desc)
(interactive "SDefine unit name: \nsDescription: ")
-
-
-;;; Units operations.
-
-;;; Units table last updated 9-Jan-91 by Ulrich Mueller (ulm@vsnhd1.cern.ch)
-;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov)
-
-(defvar math-standard-units
- '( ;; Length
- ( m nil "*Meter" )
- ( in "2.54 cm" "Inch" )
- ( ft "12 in" "Foot" )
- ( yd "3 ft" "Yard" )
- ( mi "5280 ft" "Mile" )
- ( au "1.495979e11 m" "Astronomical Unit" )
- ( lyr "9460536207068016 m" "Light Year" )
- ( pc "206264.80625 au" "Parsec" )
- ( nmi "1852 m" "Nautical Mile" )
- ( fath "6 ft" "Fathom" )
- ( u "1 um" "Micron" )
- ( mil "in/1000" "Mil" )
- ( point "in/72" "Point (1/72 inch)" )
- ( tpt "in/72.27" "Point (TeX conventions)" )
- ( Ang "1e-10 m" "Angstrom" )
- ( mfi "mi+ft+in" "Miles + feet + inches" )
-
- ;; Area
- ( hect "10000 m^2" "*Hectare" )
- ( acre "mi^2 / 640" "Acre" )
- ( b "1e-28 m^2" "Barn" )
-
- ;; Volume
- ( l "1e-3 m^3" "*Liter" )
- ( L "1e-3 m^3" "Liter" )
- ( gal "4 qt" "US Gallon" )
- ( qt "2 pt" "Quart" )
- ( pt "2 cup" "Pint" )
- ( cup "8 ozfl" "Cup" )
- ( ozfl "2 tbsp" "Fluid Ounce" )
- ( floz "2 tbsp" "Fluid Ounce" )
- ( tbsp "3 tsp" "Tablespoon" )
- ( tsp "4.92892159375 ml" "Teaspoon" )
- ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" )
- ( galC "4.54609 l" "Canadian Gallon" )
- ( galUK "4.546092 l" "UK Gallon" )
-
- ;; Time
- ( s nil "*Second" )
- ( sec "s" "Second" )
- ( min "60 s" "Minute" )
- ( hr "60 min" "Hour" )
- ( day "24 hr" "Day" )
- ( wk "7 day" "Week" )
- ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" )
- ( yr "365.25 day" "Year" )
- ( Hz "1/s" "Hertz" )
-
- ;; Speed
- ( mph "mi/hr" "*Miles per hour" )
- ( kph "km/hr" "Kilometers per hour" )
- ( knot "nmi/hr" "Knot" )
- ( c "2.99792458e8 m/s" "Speed of light" )
-
- ;; Acceleration
- ( ga "9.80665 m/s^2" "*\"g\" acceleration" )
-
- ;; Mass
- ( g nil "*Gram" )
- ( lb "16 oz" "Pound (mass)" )
- ( oz "28.349523125 g" "Ounce (mass)" )
- ( ton "2000 lb" "Ton" )
- ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
- ( t "1000 kg" "Metric ton" )
- ( tonUK "1016.0469088 kg" "UK ton" )
- ( lbt "12 ozt" "Troy pound" )
- ( ozt "31.103475 g" "Troy ounce" )
- ( ct ".2 g" "Carat" )
- ( amu "1.6605402e-24 g" "Unified atomic mass" )
-
- ;; Force
- ( N "m kg/s^2" "*Newton" )
- ( dyn "1e-5 N" "Dyne" )
- ( gf "ga g" "Gram (force)" )
- ( lbf "4.44822161526 N" "Pound (force)" )
- ( kip "1000 lbf" "Kilopound (force)" )
- ( pdl "0.138255 N" "Poundal" )
-
- ;; Energy
- ( J "N m" "*Joule" )
- ( erg "1e-7 J" "Erg" )
- ( cal "4.1868 J" "International Table Calorie" )
- ( Btu "1055.05585262 J" "International Table Btu" )
- ( eV "ech V" "Electron volt" )
- ( ev "eV" "Electron volt" )
- ( therm "105506000 J" "EEC therm" )
- ( invcm "h c/cm" "Energy in inverse centimeters" )
- ( Kayser "invcm" "Kayser (inverse centimeter energy)" )
- ( men "100/invcm" "Inverse energy in meters" )
- ( Hzen "h Hz" "Energy in Hertz")
- ( Ken "k K" "Energy in Kelvins")
- ;; ( invcm "eV / 8065.47835185" "Energy in inverse centimeters" )
- ;; ( Hzen "eV / 2.41796958004e14" "Energy in Hertz")
- ;; ( Ken "eV / 11604.7967327" "Energy in Kelvins")
-
- ;; Power
- ( W "J/s" "*Watt" )
- ( hp "745.7 W" "Horsepower" )
-
- ;; Temperature
- ( K nil "*Degree Kelvin" K )
- ( dK "K" "Degree Kelvin" K )
- ( degK "K" "Degree Kelvin" K )
- ( dC "K" "Degree Celsius" C )
- ( degC "K" "Degree Celsius" C )
- ( dF "(5/9) K" "Degree Fahrenheit" F )
- ( degF "(5/9) K" "Degree Fahrenheit" F )
-
- ;; Pressure
- ( Pa "N/m^2" "*Pascal" )
- ( bar "1e5 Pa" "Bar" )
- ( atm "101325 Pa" "Standard atmosphere" )
- ( torr "atm/760" "Torr" )
- ( mHg "1000 torr" "Meter of mercury" )
- ( inHg "25.4 mmHg" "Inch of mercury" )
- ( inH2O "248.84 Pa" "Inch of water" )
- ( psi "6894.75729317 Pa" "Pound per square inch" )
-
- ;; Viscosity
- ( P "0.1 Pa s" "*Poise" )
- ( St "1e-4 m^2/s" "Stokes" )
-
- ;; Electromagnetism
- ( A nil "*Ampere" )
- ( C "A s" "Coulomb" )
- ( Fdy "ech Nav" "Faraday" )
- ( e "1.60217733e-19 C" "Elementary charge" )
- ( ech "1.60217733e-19 C" "Elementary charge" )
- ( V "W/A" "Volt" )
- ( ohm "V/A" "Ohm" )
- ( mho "A/V" "Mho" )
- ( S "A/V" "Siemens" )
- ( F "C/V" "Farad" )
- ( H "Wb/A" "Henry" )
- ( T "Wb/m^2" "Tesla" )
- ( G "1e-4 T" "Gauss" )
- ( Wb "V s" "Weber" )
-
- ;; Luminous intensity
- ( cd nil "*Candela" )
- ( sb "1e4 cd/m^2" "Stilb" )
- ( lm "cd sr" "Lumen" )
- ( lx "lm/m^2" "Lux" )
- ( ph "1e4 lx" "Phot" )
- ( fc "10.76 lx" "Footcandle" )
- ( lam "1e4 lm/m^2" "Lambert" )
- ( flam "1.07639104e-3 lam" "Footlambert" )
-
- ;; Radioactivity
- ( Bq "1/s" "*Becquerel" )
- ( Ci "3.7e10 Bq" "Curie" )
- ( Gy "J/kg" "Gray" )
- ( Sv "Gy" "Sievert" )
- ( R "2.58e-4 C/kg" "Roentgen" )
- ( rd ".01 Gy" "Rad" )
- ( rem "rd" "Rem" )
-
- ;; Amount of substance
- ( mol nil "*Mole" )
-
- ;; Plane angle
- ( rad nil "*Radian" )
- ( circ "2 pi rad" "Full circle" )
- ( rev "circ" "Full revolution" )
- ( deg "circ/360" "Degree" )
- ( arcmin "deg/60" "Arc minute" )
- ( arcsec "arcmin/60" "Arc second" )
- ( grad "circ/400" "Grade" )
- ( rpm "rev/min" "Revolutions per minute" )
-
- ;; Solid angle
- ( sr nil "*Steradian" )
-
- ;; Other physical quantities (Physics Letters B239, 1 (1990))
- ( h "6.6260755e-34 J s" "*Planck's constant" )
- ( hbar "h / 2 pi" "Planck's constant" )
- ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" )
- ( Grav "6.67259e-11 N m^2/kg^2" "Gravitational constant" )
- ( Nav "6.0221367e23 / mol" "Avagadro's constant" )
- ( me "0.51099906 MeV/c^2" "Electron rest mass" )
- ( mp "1.007276470 amu" "Proton rest mass" )
- ( mn "1.008664904 amu" "Neutron rest mass" )
- ( mu "0.113428913 amu" "Muon rest mass" )
- ( Ryd "1.0973731571e5 invcm" "Rydberg's constant" )
- ( k "1.3806513e-23 J/K" "Boltzmann's constant" )
- ( fsc "1 / 137.0359895" "Fine structure constant" )
- ( muB "5.78838263e-11 MeV/T" "Bohr magneton" )
- ( muN "3.15245166e-14 MeV/T" "Nuclear magneton" )
- ( mue "1.001159652193 muB" "Electron magnetic moment" )
- ( mup "2.792847386 muN" "Proton magnetic moment" )
- ( R0 "Nav k" "Molar gas constant" )
- ( V0 "22.413992 L/mol" "Standard volume of ideal gas" )
-))
-
-
-(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
-that the combined units table will be rebuilt.")
-
-(defvar math-unit-prefixes
- '( ( ?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" )
-))
-
-(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 ) ) ) )
-))
-
-(defvar math-units-table nil
- "Internal units table derived from math-defined-units.
-Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
-
-(defvar math-units-table-buffer-valid nil)
-
-
(defun math-build-units-table ()
(or math-units-table
(let* ((combined-units (append math-additional-units
expr
(list '* expr units)))))
+(defvar math-decompose-units-cache nil)
(defun math-decompose-units (units)
(let ((u (math-check-unit-name units)))
(and u (eq (car-safe (nth 1 u)) '+)
(setq ulist (cons (math-decompose-unit-part utemp) ulist)
utemp ulist)
(while (setq utemp (cdr utemp))
- (or (equal (nth 2 (car utemp)) (nth 2 (car ulist)))
- (error "Inconsistent units in sum")))
+ (unless (equal (nth 2 (car utemp)) (nth 2 (car ulist)))
+ (error "Inconsistent units in sum")))
(setq math-decompose-units-cache
(cons entry
(sort ulist
(not (Math-lessp (nth 1 x)
(nth 1 y))))))))))
(cdr math-decompose-units-cache))))
-(setq math-decompose-units-cache nil)
(defun math-decompose-unit-part (unit)
(cons unit
(math-pow (math-div (car compat) new-units)
(cdr compat))
nil))))
- (if (setq unit-list (math-decompose-units new-units))
- (setq new-units (nth 2 (car unit-list))))
- (if (eq (car-safe expr) '+)
- (setq expr (math-simplify-units expr)))
+ (when (setq unit-list (math-decompose-units new-units))
+ (setq new-units (nth 2 (car unit-list))))
+ (when (eq (car-safe expr) '+)
+ (setq expr (math-simplify-units expr)))
(if (math-units-in-expr-p expr t)
(math-convert-units-rec expr)
(math-apply-units (math-to-standard-units
(error "Inconsistent temperature units"))
units))
(unew (math-check-unit-name new)))
- (or (and (consp unew) (nth 3 unew))
- (error "Not a valid temperature unit"))
- (or (and (consp uold) (nth 3 uold))
- (error "Not a pure temperature expression"))
+ (unless (and (consp unew) (nth 3 unew))
+ (error "Not a valid temperature unit"))
+ (unless (and (consp uold) (nth 3 uold))
+ (error "Not a pure temperature expression"))
(let ((v (car uold)))
(setq expr (list '/ expr (list 'var v
(intern (concat "var-"
(let ((math-simplifying-units t)
(calc-matrix-mode 'scalar))
(math-simplify a)))
-(defalias calcFunc-usimplify 'math-simplify-units)
+(defalias 'calcFunc-usimplify 'math-simplify-units)
(math-defsimplify (+ -)
(and math-simplifying-units
(let ((n (car np))
d dd temp)
(while (eq (car-safe (setq d (car dp))) '*)
- (if (setq temp (math-simplify-units-quotient n (nth 1 d)))
- (progn
- (setcar np (setq n temp))
- (setcar (cdr d) 1)))
+ (when (setq temp (math-simplify-units-quotient n (nth 1 d)))
+ (setcar np (setq n temp))
+ (setcar (cdr d) 1))
(setq dp (cdr (cdr d))))
- (if (setq temp (math-simplify-units-quotient n d))
- (progn
- (setcar np (setq n temp))
- (setcar dp 1)))))
+ (when (setq temp (math-simplify-units-quotient n d))
+ (setcar np (setq n temp))
+ (setcar dp 1))))
;; Simplify, e.g., "in / cm" to "2.54" in a units expression.
(defun math-simplify-units-quotient (n d)
(let ((pow1 1)
(pow2 1))
- (and (eq (car-safe n) '^)
- (integerp (nth 2 n))
- (setq pow1 (nth 2 n) n (nth 1 n)))
- (and (eq (car-safe d) '^)
- (integerp (nth 2 d))
- (setq pow2 (nth 2 d) d (nth 1 d)))
+ (when (and (eq (car-safe n) '^)
+ (integerp (nth 2 n)))
+ (setq pow1 (nth 2 n) n (nth 1 n)))
+ (when (and (eq (car-safe d) '^)
+ (integerp (nth 2 d)))
+ (setq pow2 (nth 2 d) d (nth 1 d)))
(let ((un (math-check-unit-name n))
(ud (math-check-unit-name d)))
(and un ud
(while uptr
(setq u (car uptr)
name (nth 2 u))
- (if (eq (car u) 'm)
- (setq std t))
+ (when (eq (car u) 'm)
+ (setq std t))
(setq shadowed (and std (assq (car u) math-additional-units)))
- (if (and name
- (> (length name) 1)
- (eq (aref name 0) ?\*))
- (progn
- (or (eq uptr math-units-table)
- (insert "\n"))
- (setq name (substring name 1))))
+ (when (and name
+ (> (length name) 1)
+ (eq (aref name 0) ?\*))
+ (unless (eq uptr math-units-table)
+ (insert "\n"))
+ (setq name (substring name 1)))
(insert " ")
(and shadowed (insert "("))
(insert (symbol-name (car u)))
(and shadowed (insert ")"))
(indent-to 41)
(insert " ")
- (if name
- (insert name))
+ (when name
+ (insert name))
(if shadowed
(insert " (redefined above)")
- (or (nth 1 u)
- (insert " (base unit)")))
+ (unless (nth 1 u)
+ (insert " (base unit)")))
(insert "\n")
(setq uptr (cdr uptr)))
(insert "\n\nUnit Prefix Table:\n\n")