Mercurial > emacs
annotate lisp/calc/calc-units.el @ 58617:48bd22b33f65
(init_cmdargs): Set unibyte strings in Vcommand_line_args.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 29 Nov 2004 07:16:09 +0000 |
parents | 0a3797785946 |
children | 5ef7cf7f3b8f |
rev | line source |
---|---|
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1 ;;; calc-units.el --- unit conversion functions for Calc |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
2 |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
4 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 ;; accepts responsibility to anyone for the consequences of using it | |
13 ;; or for whether it serves any particular purpose or works at all, | |
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 ;; License for full details. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; GNU Emacs General Public License. A copy of this license is | |
20 ;; supposed to have been given to you along with GNU Emacs so you | |
21 ;; can know your rights and responsibilities. It should be in a | |
22 ;; file named COPYING. Among other things, the copyright notice | |
23 ;; and this notice must be preserved on all copies. | |
24 | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
25 ;;; Commentary: |
40785 | 26 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 ;; This file is autoloaded from calc-ext.el. | |
30 (require 'calc-ext) | |
31 | |
32 (require 'calc-macs) | |
33 | |
34 (defun calc-Need-calc-units () nil) | |
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) | |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
40 ;;; Updated April 2002 by Jochen Küpper |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
41 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
42 ;;; for CODATA 1998 see one of |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
43 ;;; - Journal of Physical and Chemical Reference Data, 28(6), 1713-1852, 1999. |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
44 ;;; - Reviews of Modern Physics, 72(2), 351-495, 2000. |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
45 ;;; - http://physics.nist.gov/cuu/Constants/index.html |
40785 | 46 |
47 (defvar math-standard-units | |
48 '( ;; Length | |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
49 ( m nil "*Meter" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
50 ( in "2.54 cm" "Inch" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
51 ( ft "12 in" "Foot" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
52 ( yd "3 ft" "Yard" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
53 ( mi "5280 ft" "Mile" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
54 ( au "149597870691 m" "Astronomical Unit" ) ;; NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
55 ( lyr "9460536207068016 m" "Light Year" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
56 ( pc "206264.80625 au" "Parsec" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
57 ( nmi "1852 m" "Nautical Mile" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
58 ( fath "6 ft" "Fathom" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
59 ( u "1 um" "Micron" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
60 ( mil "in/1000" "Mil" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
61 ( point "in/72" "Point (1/72 inch)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
62 ( tpt "in/72.27" "Point (TeX conventions)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
63 ( Ang "1e-10 m" "Angstrom" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
64 ( mfi "mi+ft+in" "Miles + feet + inches" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
65 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
66 ;; Area |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
67 ( hect "10000 m^2" "*Hectare" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
68 ( acre "mi^2 / 640" "Acre" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
69 ( b "1e-28 m^2" "Barn" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
70 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
71 ;; Volume |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
72 ( l "1e-3 m^3" "*Liter" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
73 ( L "1e-3 m^3" "Liter" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
74 ( gal "4 qt" "US Gallon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
75 ( qt "2 pt" "Quart" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
76 ( pt "2 cup" "Pint" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
77 ( cup "8 ozfl" "Cup" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
78 ( ozfl "2 tbsp" "Fluid Ounce" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
79 ( floz "2 tbsp" "Fluid Ounce" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
80 ( tbsp "3 tsp" "Tablespoon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
81 ( tsp "4.92892159375 ml" "Teaspoon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
82 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
83 ( galC "4.54609 l" "Canadian Gallon" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
84 ( galUK "4.546092 l" "UK Gallon" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
85 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
86 ;; Time |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
87 ( s nil "*Second" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
88 ( sec "s" "Second" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
89 ( min "60 s" "Minute" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
90 ( hr "60 min" "Hour" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
91 ( day "24 hr" "Day" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
92 ( wk "7 day" "Week" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
93 ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
94 ( yr "365.25 day" "Year" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
95 ( Hz "1/s" "Hertz" ) |
40785 | 96 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
97 ;; Speed |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
98 ( mph "mi/hr" "*Miles per hour" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
99 ( kph "km/hr" "Kilometers per hour" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
100 ( knot "nmi/hr" "Knot" ) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
101 ( c "2.99792458e8 m/s" "Speed of light" ) |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
102 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
103 ;; Acceleration |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
104 ( ga "9.80665 m/s^2" "*\"g\" acceleration" ) |
40785 | 105 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
106 ;; Mass |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
107 ( g nil "*Gram" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
108 ( lb "16 oz" "Pound (mass)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
109 ( oz "28.349523125 g" "Ounce (mass)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
110 ( ton "2000 lb" "Ton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
111 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
112 ( t "1000 kg" "Metric ton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
113 ( tonUK "1016.0469088 kg" "UK ton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
114 ( lbt "12 ozt" "Troy pound" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
115 ( ozt "31.103475 g" "Troy ounce" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
116 ( ct ".2 g" "Carat" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
117 ( amu "1.66053873e-27 kg" "Unified atomic mass" ) ;; CODATA 1998 |
40785 | 118 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
119 ;; Force |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
120 ( N "m kg/s^2" "*Newton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
121 ( dyn "1e-5 N" "Dyne" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
122 ( gf "ga g" "Gram (force)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
123 ( lbf "4.44822161526 N" "Pound (force)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
124 ( kip "1000 lbf" "Kilopound (force)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
125 ( pdl "0.138255 N" "Poundal" ) |
40785 | 126 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
127 ;; Energy |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
128 ( J "N m" "*Joule" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
129 ( erg "1e-7 J" "Erg" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
130 ( cal "4.1868 J" "International Table Calorie" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
131 ( Btu "1055.05585262 J" "International Table Btu" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
132 ( eV "ech V" "Electron volt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
133 ( ev "eV" "Electron volt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
134 ( therm "105506000 J" "EEC therm" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
135 ( invcm "h c/cm" "Energy in inverse centimeters" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
136 ( Kayser "invcm" "Kayser (inverse centimeter energy)" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
137 ( men "100/invcm" "Inverse energy in meters" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
138 ( Hzen "h Hz" "Energy in Hertz") |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
139 ( Ken "k K" "Energy in Kelvins") |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
140 ( Wh "W h" "Watt hour") |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
141 ( Ws "W s" "Watt second") |
40785 | 142 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
143 ;; Power |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
144 ( W "J/s" "*Watt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
145 ( hp "745.7 W" "Horsepower" ) |
40785 | 146 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
147 ;; Temperature |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
148 ( K nil "*Degree Kelvin" K ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
149 ( dK "K" "Degree Kelvin" K ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
150 ( degK "K" "Degree Kelvin" K ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
151 ( dC "K" "Degree Celsius" C ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
152 ( degC "K" "Degree Celsius" C ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
153 ( dF "(5/9) K" "Degree Fahrenheit" F ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
154 ( degF "(5/9) K" "Degree Fahrenheit" F ) |
40785 | 155 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
156 ;; Pressure |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
157 ( Pa "N/m^2" "*Pascal" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
158 ( bar "1e5 Pa" "Bar" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
159 ( atm "101325 Pa" "Standard atmosphere" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
160 ( torr " 1.333224e2 Pa" "Torr" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
161 ( mHg "1000 torr" "Meter of mercury" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
162 ( inHg "25.4 mmHg" "Inch of mercury" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
163 ( inH2O "2.490889e2 Pa" "Inch of water" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
164 ( psi "6894.75729317 Pa" "Pound per square inch" ) |
40785 | 165 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
166 ;; Viscosity |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
167 ( P "0.1 Pa s" "*Poise" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
168 ( St "1e-4 m^2/s" "Stokes" ) |
40785 | 169 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
170 ;; Electromagnetism |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
171 ( A nil "*Ampere" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
172 ( C "A s" "Coulomb" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
173 ( Fdy "ech Nav" "Faraday" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
174 ( e "1.602176462e-19 C" "Elementary charge" ) ;; CODATA 1998 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
175 ( ech "1.602176462e-19 C" "Elementary charge" ) ;; CODATA 1998 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
176 ( V "W/A" "Volt" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
177 ( ohm "V/A" "Ohm" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
178 ( mho "A/V" "Mho" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
179 ( S "A/V" "Siemens" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
180 ( F "C/V" "Farad" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
181 ( H "Wb/A" "Henry" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
182 ( T "Wb/m^2" "Tesla" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
183 ( G "1e-4 T" "Gauss" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
184 ( Wb "V s" "Weber" ) |
40785 | 185 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
186 ;; Luminous intensity |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
187 ( cd nil "*Candela" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
188 ( sb "1e4 cd/m^2" "Stilb" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
189 ( lm "cd sr" "Lumen" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
190 ( lx "lm/m^2" "Lux" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
191 ( ph "1e4 lx" "Phot" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
192 ( fc "10.76391 lx" "Footcandle" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
193 ( lam "1e4 lm/m^2" "Lambert" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
194 ( flam "3.426259 cd/m^2" "Footlambert" ) ;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html) |
40785 | 195 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
196 ;; Radioactivity |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
197 ( Bq "1/s" "*Becquerel" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
198 ( Ci "3.7e10 Bq" "Curie" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
199 ( Gy "J/kg" "Gray" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
200 ( Sv "Gy" "Sievert" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
201 ( R "2.58e-4 C/kg" "Roentgen" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
202 ( rd ".01 Gy" "Rad" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
203 ( rem "rd" "Rem" ) |
40785 | 204 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
205 ;; Amount of substance |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
206 ( mol nil "*Mole" ) |
40785 | 207 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
208 ;; Plane angle |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
209 ( rad nil "*Radian" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
210 ( circ "2 pi rad" "Full circle" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
211 ( rev "circ" "Full revolution" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
212 ( deg "circ/360" "Degree" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
213 ( arcmin "deg/60" "Arc minute" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
214 ( arcsec "arcmin/60" "Arc second" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
215 ( grad "circ/400" "Grade" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
216 ( rpm "rev/min" "Revolutions per minute" ) |
40785 | 217 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
218 ;; Solid angle |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
219 ( sr nil "*Steradian" ) |
40785 | 220 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
221 ;; Other physical quantities (CODATA 1998) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
222 ( h "6.62606876e-34 J s" "*Planck's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
223 ( hbar "h / 2 pi" "Planck's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
224 ( mu0 "4 pi 1e-7 H/m" "Permeability of vacuum" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
225 ( Grav "6.673e-11 m^3/kg^1/s^2" "Gravitational constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
226 ( Nav "6.02214199e23 / mol" "Avagadro's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
227 ( me "9.10938188e-31 kg" "Electron rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
228 ( mp "1.67262158e-27 kg" "Proton rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
229 ( mn "1.67492716e-27 kg" "Neutron rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
230 ( mu "1.88353109e-28 kg" "Muon rest mass" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
231 ( Ryd "10973731.568549 /m" "Rydberg's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
232 ( k "1.3806503e-23 J/K" "Boltzmann's constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
233 ( fsc "7.297352533e-3" "Fine structure constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
234 ( muB "927.400899e-26 J/T" "Bohr magneton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
235 ( muN "5.05078317e-27 J/T" "Nuclear magneton" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
236 ( mue "-928.476362e-26 J/T" "Electron magnetic moment" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
237 ( mup "1.410606633e-26 J/T" "Proton magnetic moment" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
238 ( R0 "8.314472 J/mol/K" "Molar gas constant" ) |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
239 ( V0 "22.710981e-3 m^3/mol" "Standard volume of ideal gas" ))) |
40785 | 240 |
241 | |
242 (defvar math-additional-units nil | |
243 "*Additional units table for user-defined units. | |
244 Must be formatted like math-standard-units. | |
245 If this is changed, be sure to set math-units-table to nil to ensure | |
246 that the combined units table will be rebuilt.") | |
247 | |
248 (defvar math-unit-prefixes | |
249 '( ( ?E (float 1 18) "Exa" ) | |
250 ( ?P (float 1 15) "Peta" ) | |
251 ( ?T (float 1 12) "Tera" ) | |
252 ( ?G (float 1 9) "Giga" ) | |
253 ( ?M (float 1 6) "Mega" ) | |
254 ( ?k (float 1 3) "Kilo" ) | |
255 ( ?K (float 1 3) "Kilo" ) | |
256 ( ?h (float 1 2) "Hecto" ) | |
257 ( ?H (float 1 2) "Hecto" ) | |
258 ( ?D (float 1 1) "Deka" ) | |
259 ( 0 (float 1 0) nil ) | |
260 ( ?d (float 1 -1) "Deci" ) | |
261 ( ?c (float 1 -2) "Centi" ) | |
262 ( ?m (float 1 -3) "Milli" ) | |
263 ( ?u (float 1 -6) "Micro" ) | |
264 ( ?n (float 1 -9) "Nano" ) | |
265 ( ?p (float 1 -12) "Pico" ) | |
266 ( ?f (float 1 -15) "Femto" ) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
267 ( ?a (float 1 -18) "Atto" ))) |
40785 | 268 |
269 (defvar math-standard-units-systems | |
270 '( ( base nil ) | |
271 ( si ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) ) | |
272 ( mks ( ( g '(* (var kg var-kg) (float 1 -3)) ) ) ) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
273 ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) ))) |
40785 | 274 |
275 (defvar math-units-table nil | |
276 "Internal units table derived from math-defined-units. | |
277 Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |
278 | |
279 (defvar math-units-table-buffer-valid nil) | |
280 | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
281 ;;; Units commands. |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
282 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
283 (defun calc-base-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
284 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
285 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
286 (let ((calc-autorange-units nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
287 (calc-enter-result 1 "bsun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
288 (math-to-standard-units (calc-top-n 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
289 nil)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
290 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
291 (defun calc-quick-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
292 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
293 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
294 (let* ((num (- last-command-char ?0)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
295 (pos (if (= num 0) 10 num)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
296 (units (calc-var-value 'var-Units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
297 (expr (calc-top-n 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
298 (unless (and (>= num 0) (<= num 9)) |
57130
d8cdadecaba8
(calc-quick-units): Fix overzealous s/or/unless.
John Paul Wallington <jpw@pobox.com>
parents:
52401
diff
changeset
|
299 (error "Bad unit number")) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
300 (unless (math-vectorp units) |
57130
d8cdadecaba8
(calc-quick-units): Fix overzealous s/or/unless.
John Paul Wallington <jpw@pobox.com>
parents:
52401
diff
changeset
|
301 (error "No \"quick units\" are defined")) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
302 (unless (< pos (length units)) |
57130
d8cdadecaba8
(calc-quick-units): Fix overzealous s/or/unless.
John Paul Wallington <jpw@pobox.com>
parents:
52401
diff
changeset
|
303 (error "Unit number %d not defined" pos)) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
304 (if (math-units-in-expr-p expr nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
305 (calc-enter-result 1 (format "cun%d" num) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
306 (math-convert-units expr (nth pos units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
307 (calc-enter-result 1 (format "*un%d" num) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
308 (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
309 (math-mul expr (nth pos units)))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
310 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
311 (defun calc-convert-units (&optional old-units new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
312 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
313 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
314 (let ((expr (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
315 (uoldname nil) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
316 unew |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
317 units) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
318 (unless (math-units-in-expr-p expr t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
319 (let ((uold (or old-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
320 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
321 (setq uoldname (read-string "Old units: ")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
322 (if (equal uoldname "") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
323 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
324 (setq uoldname "1") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
325 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
326 (if (string-match "\\` */" uoldname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
327 (setq uoldname (concat "1" uoldname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
328 (math-read-expr uoldname)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
329 (when (eq (car-safe uold) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
330 (error "Bad format in units expression: %s" (nth 1 uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
331 (setq expr (math-mul expr uold)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
332 (unless new-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
333 (setq new-units (read-string (if uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
334 (concat "Old units: " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
335 uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
336 ", new units: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
337 "New units: ")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
338 (when (string-match "\\` */" new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
339 (setq new-units (concat "1" new-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
340 (setq units (math-read-expr new-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
341 (when (eq (car-safe units) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
342 (error "Bad format in units expression: %s" (nth 2 units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
343 (let ((unew (math-units-in-expr-p units t)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
344 (std (and (eq (car-safe units) 'var) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
345 (assq (nth 1 units) math-standard-units-systems)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
346 (if std |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
347 (calc-enter-result 1 "cvun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
348 (math-to-standard-units expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
349 (nth 1 std)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
350 (unless unew |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
351 (error "No units specified")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
352 (calc-enter-result 1 "cvun" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
353 (math-convert-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
354 expr units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
355 (and uoldname (not (equal uoldname "1")))))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
356 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
357 (defun calc-autorange-units (arg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
358 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
359 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
360 (calc-change-mode 'calc-autorange-units arg nil t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
361 (message (if calc-autorange-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
362 "Adjusting target unit prefix automatically" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
363 "Using target units exactly")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
364 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
365 (defun calc-convert-temperature (&optional old-units new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
366 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
367 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
368 (let ((expr (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
369 (uold nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
370 (uoldname nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
371 unew) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
372 (setq uold (or old-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
373 (let ((units (math-single-units-in-expr-p expr))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
374 (if units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
375 (if (consp units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
376 (list 'var (car units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
377 (intern (concat "var-" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
378 (symbol-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
379 (car units))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
380 (error "Not a pure temperature expression")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
381 (math-read-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
382 (setq uoldname (read-string |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
383 "Old temperature units: "))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
384 (when (eq (car-safe uold) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
385 (error "Bad format in units expression: %s" (nth 2 uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
386 (or (math-units-in-expr-p expr nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
387 (setq expr (math-mul expr uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
388 (setq unew (or new-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
389 (math-read-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
390 (read-string (if uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
391 (concat "Old temperature units: " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
392 uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
393 ", new units: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
394 "New temperature units: "))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
395 (when (eq (car-safe unew) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
396 (error "Bad format in units expression: %s" (nth 2 unew))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
397 (calc-enter-result 1 "cvtm" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
398 (math-convert-temperature expr uold unew |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
399 uoldname)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
400 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
401 (defun calc-remove-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
402 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
403 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
404 (calc-enter-result 1 "rmun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
405 (math-remove-units (calc-top-n 1)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
406 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
407 (defun calc-extract-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
408 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
409 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
410 (calc-enter-result 1 "rmun" (math-simplify-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
411 (math-extract-units (calc-top-n 1)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
412 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
413 ;; The variables calc-num-units and calc-den-units are local to |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
414 ;; calc-explain-units, but are used by calc-explain-units-rec, |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
415 ;; which is called by calc-explain-units. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
416 (defvar calc-num-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
417 (defvar calc-den-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
418 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
419 (defun calc-explain-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
420 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
421 (calc-wrapper |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
422 (let ((calc-num-units nil) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
423 (calc-den-units nil)) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
424 (calc-explain-units-rec (calc-top-n 1) 1) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
425 (and calc-den-units (string-match "^[^(].* .*[^)]$" calc-den-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
426 (setq calc-den-units (concat "(" calc-den-units ")"))) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
427 (if calc-num-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
428 (if calc-den-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
429 (message "%s per %s" calc-num-units calc-den-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
430 (message "%s" calc-num-units)) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
431 (if calc-den-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
432 (message "1 per %s" calc-den-units) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
433 (message "No units in expression")))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
434 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
435 (defun calc-explain-units-rec (expr pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
436 (let ((u (math-check-unit-name expr)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
437 pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
438 (if (and u (not (math-zerop pow))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
439 (let ((name (or (nth 2 u) (symbol-name (car u))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
440 (if (eq (aref name 0) ?\*) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
441 (setq name (substring name 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
442 (if (string-match "[^a-zA-Z0-9']" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
443 (if (string-match "^[a-zA-Z0-9' ()]*$" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
444 (while (setq pos (string-match "[ ()]" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
445 (setq name (concat (substring name 0 pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
446 (if (eq (aref name pos) 32) "-" "") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
447 (substring name (1+ pos))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
448 (setq name (concat "(" name ")")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
449 (or (eq (nth 1 expr) (car u)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
450 (setq name (concat (nth 2 (assq (aref (symbol-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
451 (nth 1 expr)) 0) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
452 math-unit-prefixes)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
453 (if (and (string-match "[^a-zA-Z0-9']" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
454 (not (memq (car u) '(mHg gf)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
455 (concat "-" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
456 (downcase name))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
457 (cond ((or (math-equal-int pow 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
458 (math-equal-int pow -1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
459 ((or (math-equal-int pow 2) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
460 (math-equal-int pow -2)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
461 (if (equal (nth 4 u) '((m . 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
462 (setq name (concat "Square-" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
463 (setq name (concat name "-squared")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
464 ((or (math-equal-int pow 3) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
465 (math-equal-int pow -3)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
466 (if (equal (nth 4 u) '((m . 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
467 (setq name (concat "Cubic-" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
468 (setq name (concat name "-cubed")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
469 (t |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
470 (setq name (concat name "^" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
471 (math-format-number (math-abs pow)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
472 (if (math-posp pow) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
473 (setq calc-num-units (if calc-num-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
474 (concat calc-num-units " " name) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
475 name)) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
476 (setq calc-den-units (if calc-den-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
477 (concat calc-den-units " " name) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
478 name)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
479 (cond ((eq (car-safe expr) '*) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
480 (calc-explain-units-rec (nth 1 expr) pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
481 (calc-explain-units-rec (nth 2 expr) pow)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
482 ((eq (car-safe expr) '/) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
483 (calc-explain-units-rec (nth 1 expr) pow) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
484 (calc-explain-units-rec (nth 2 expr) (- pow))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
485 ((memq (car-safe expr) '(neg + -)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
486 (calc-explain-units-rec (nth 1 expr) pow)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
487 ((and (eq (car-safe expr) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
488 (math-realp (nth 2 expr))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
489 (calc-explain-units-rec (nth 1 expr) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
490 (math-mul pow (nth 2 expr)))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
491 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
492 (defun calc-simplify-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
493 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
494 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
495 (calc-with-default-simplification |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
496 (calc-enter-result 1 "smun" (math-simplify-units (calc-top-n 1)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
497 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
498 (defun calc-view-units-table (n) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
499 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
500 (and n (setq math-units-table-buffer-valid nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
501 (let ((win (get-buffer-window "*Units Table*"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
502 (if (and win |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
503 math-units-table |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
504 math-units-table-buffer-valid) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
505 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
506 (bury-buffer (window-buffer win)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
507 (let ((curwin (selected-window))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
508 (select-window win) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
509 (switch-to-buffer nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
510 (select-window curwin))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
511 (math-build-units-table-buffer nil)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
512 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
513 (defun calc-enter-units-table (n) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
514 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
515 (and n (setq math-units-table-buffer-valid nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
516 (math-build-units-table-buffer t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
517 (message (substitute-command-keys "Type \\[calc] to return to the Calculator"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
518 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
519 (defun calc-define-unit (uname desc) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
520 (interactive "SDefine unit name: \nsDescription: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
521 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
522 (let ((form (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
523 (unit (assq uname math-additional-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
524 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
525 (setq math-additional-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
526 (cons (setq unit (list uname nil nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
527 math-additional-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
528 math-units-table nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
529 (setcar (cdr unit) (and (not (and (eq (car-safe form) 'var) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
530 (eq (nth 1 form) uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
531 (not (math-equal-int form 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
532 (math-format-flat-expr form 0))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
533 (setcar (cdr (cdr unit)) (and (not (equal desc "")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
534 desc)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
535 (calc-invalidate-units-table)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
536 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
537 (defun calc-undefine-unit (uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
538 (interactive "SUndefine unit name: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
539 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
540 (let ((unit (assq uname math-additional-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
541 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
542 (if (assq uname math-standard-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
543 (error "\"%s\" is a predefined unit name" uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
544 (error "Unit name \"%s\" not found" uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
545 (setq math-additional-units (delq unit math-additional-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
546 math-units-table nil))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
547 (calc-invalidate-units-table)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
548 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
549 (defun calc-invalidate-units-table () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
550 (setq math-units-table nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
551 (let ((buf (get-buffer "*Units Table*"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
552 (and buf |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
553 (save-excursion |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
554 (set-buffer buf) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
555 (save-excursion |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
556 (goto-char (point-min)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
557 (if (looking-at "Calculator Units Table") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
558 (let ((buffer-read-only nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
559 (insert "(Obsolete) ")))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
560 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
561 (defun calc-get-unit-definition (uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
562 (interactive "SGet definition for unit: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
563 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
564 (math-build-units-table) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
565 (let ((unit (assq uname math-units-table))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
566 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
567 (error "Unit name \"%s\" not found" uname)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
568 (let ((msg (nth 2 unit))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
569 (if (stringp msg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
570 (if (string-match "^\\*" msg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
571 (setq msg (substring msg 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
572 (setq msg (symbol-name uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
573 (if (nth 1 unit) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
574 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
575 (calc-enter-result 0 "ugdf" (nth 1 unit)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
576 (message "Derived unit: %s" msg)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
577 (calc-enter-result 0 "ugdf" (list 'var uname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
578 (intern |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
579 (concat "var-" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
580 (symbol-name uname))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
581 (message "Base unit: %s" msg)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
582 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
583 (defun calc-permanent-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
584 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
585 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
586 (let (pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
587 (set-buffer (find-file-noselect (substitute-in-file-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
588 calc-settings-file))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
589 (goto-char (point-min)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
590 (if (and (search-forward ";;; Custom units stored by Calc" nil t) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
591 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
592 (beginning-of-line) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
593 (setq pos (point)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
594 (search-forward "\n;;; End of custom units" nil t))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
595 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
596 (beginning-of-line) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
597 (forward-line 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
598 (delete-region pos (point))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
599 (goto-char (point-max)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
600 (insert "\n\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
601 (forward-char -1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
602 (insert ";;; Custom units stored by Calc on " (current-time-string) "\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
603 (if math-additional-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
604 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
605 (insert "(setq math-additional-units '(\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
606 (let ((list math-additional-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
607 (while list |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
608 (insert " (" (symbol-name (car (car list))) " " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
609 (if (nth 1 (car list)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
610 (if (stringp (nth 1 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
611 (prin1-to-string (nth 1 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
612 (prin1-to-string (math-format-flat-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
613 (nth 1 (car list)) 0))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
614 "nil") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
615 " " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
616 (prin1-to-string (nth 2 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
617 ")\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
618 (setq list (cdr list)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
619 (insert "))\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
620 (insert ";;; (no custom units defined)\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
621 (insert ";;; End of custom units\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
622 (save-buffer)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
623 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
624 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
625 ;; The variable math-cu-unit-list is local to math-build-units-table, |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
626 ;; but is used by math-compare-unit-names, which is called (indirectly) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
627 ;; by math-build-units-table. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
628 ;; math-cu-unit-list is also local to math-convert-units, but is used |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
629 ;; by math-convert-units-rec, which is called by math-convert-units. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
630 (defvar math-cu-unit-list) |
40785 | 631 |
632 (defun math-build-units-table () | |
633 (or math-units-table | |
634 (let* ((combined-units (append math-additional-units | |
635 math-standard-units)) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
636 (math-cu-unit-list (mapcar 'car combined-units)) |
40785 | 637 tab) |
638 (message "Building units table...") | |
639 (setq math-units-table-buffer-valid nil) | |
640 (setq tab (mapcar (function | |
641 (lambda (x) | |
642 (list (car x) | |
643 (and (nth 1 x) | |
644 (if (stringp (nth 1 x)) | |
645 (let ((exp (math-read-plain-expr | |
646 (nth 1 x)))) | |
647 (if (eq (car-safe exp) 'error) | |
648 (error "Format error in definition of %s in units table: %s" | |
649 (car x) (nth 2 exp)) | |
650 exp)) | |
651 (nth 1 x))) | |
652 (nth 2 x) | |
653 (nth 3 x) | |
654 (and (not (nth 1 x)) | |
655 (list (cons (car x) 1)))))) | |
656 combined-units)) | |
657 (let ((math-units-table tab)) | |
658 (mapcar 'math-find-base-units tab)) | |
659 (message "Building units table...done") | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
660 (setq math-units-table tab)))) |
40785 | 661 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
662 ;; The variables math-fbu-base and math-fbu-entry are local to |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
663 ;; math-find-base-units, but are used by math-find-base-units-rec, |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
664 ;; which is called by math-find-base-units. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
665 (defvar math-fbu-base) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
666 (defvar math-fbu-entry) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
667 |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
668 (defun math-find-base-units (math-fbu-entry) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
669 (if (eq (nth 4 math-fbu-entry) 'boom) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
670 (error "Circular definition involving unit %s" (car math-fbu-entry))) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
671 (or (nth 4 math-fbu-entry) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
672 (let (math-fbu-base) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
673 (setcar (nthcdr 4 math-fbu-entry) 'boom) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
674 (math-find-base-units-rec (nth 1 math-fbu-entry) 1) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
675 '(or math-fbu-base |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
676 (error "Dimensionless definition for unit %s" (car math-fbu-entry))) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
677 (while (eq (cdr (car math-fbu-base)) 0) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
678 (setq math-fbu-base (cdr math-fbu-base))) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
679 (let ((b math-fbu-base)) |
40785 | 680 (while (cdr b) |
681 (if (eq (cdr (car (cdr b))) 0) | |
682 (setcdr b (cdr (cdr b))) | |
683 (setq b (cdr b))))) | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
684 (setq math-fbu-base (sort math-fbu-base 'math-compare-unit-names)) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
685 (setcar (nthcdr 4 math-fbu-entry) math-fbu-base) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
686 math-fbu-base))) |
40785 | 687 |
688 (defun math-compare-unit-names (a b) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
689 (memq (car b) (cdr (memq (car a) math-cu-unit-list)))) |
40785 | 690 |
691 (defun math-find-base-units-rec (expr pow) | |
692 (let ((u (math-check-unit-name expr))) | |
693 (cond (u | |
694 (let ((ulist (math-find-base-units u))) | |
695 (while ulist | |
696 (let ((p (* (cdr (car ulist)) pow)) | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
697 (old (assq (car (car ulist)) math-fbu-base))) |
40785 | 698 (if old |
699 (setcdr old (+ (cdr old) p)) | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
700 (setq math-fbu-base |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
701 (cons (cons (car (car ulist)) p) math-fbu-base)))) |
40785 | 702 (setq ulist (cdr ulist))))) |
703 ((math-scalarp expr)) | |
704 ((and (eq (car expr) '^) | |
705 (integerp (nth 2 expr))) | |
706 (math-find-base-units-rec (nth 1 expr) (* pow (nth 2 expr)))) | |
707 ((eq (car expr) '*) | |
708 (math-find-base-units-rec (nth 1 expr) pow) | |
709 (math-find-base-units-rec (nth 2 expr) pow)) | |
710 ((eq (car expr) '/) | |
711 (math-find-base-units-rec (nth 1 expr) pow) | |
712 (math-find-base-units-rec (nth 2 expr) (- pow))) | |
713 ((eq (car expr) 'neg) | |
714 (math-find-base-units-rec (nth 1 expr) pow)) | |
715 ((eq (car expr) '+) | |
716 (math-find-base-units-rec (nth 1 expr) pow)) | |
717 ((eq (car expr) 'var) | |
718 (or (eq (nth 1 expr) 'pi) | |
719 (error "Unknown name %s in defining expression for unit %s" | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
720 (nth 1 expr) (car math-fbu-entry)))) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
721 (t (error "Malformed defining expression for unit %s" (car math-fbu-entry)))))) |
40785 | 722 |
723 | |
724 (defun math-units-in-expr-p (expr sub-exprs) | |
725 (and (consp expr) | |
726 (if (eq (car expr) 'var) | |
727 (math-check-unit-name expr) | |
728 (and (or sub-exprs | |
729 (memq (car expr) '(* / ^))) | |
730 (or (math-units-in-expr-p (nth 1 expr) sub-exprs) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
731 (math-units-in-expr-p (nth 2 expr) sub-exprs)))))) |
40785 | 732 |
733 (defun math-only-units-in-expr-p (expr) | |
734 (and (consp expr) | |
735 (if (eq (car expr) 'var) | |
736 (math-check-unit-name expr) | |
737 (if (memq (car expr) '(* /)) | |
738 (and (math-only-units-in-expr-p (nth 1 expr)) | |
739 (math-only-units-in-expr-p (nth 2 expr))) | |
740 (and (eq (car expr) '^) | |
741 (and (math-only-units-in-expr-p (nth 1 expr)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
742 (math-realp (nth 2 expr)))))))) |
40785 | 743 |
744 (defun math-single-units-in-expr-p (expr) | |
745 (cond ((math-scalarp expr) nil) | |
746 ((eq (car expr) 'var) | |
747 (math-check-unit-name expr)) | |
748 ((eq (car expr) '*) | |
749 (let ((u1 (math-single-units-in-expr-p (nth 1 expr))) | |
750 (u2 (math-single-units-in-expr-p (nth 2 expr)))) | |
751 (or (and u1 u2 'wrong) | |
752 u1 | |
753 u2))) | |
754 ((eq (car expr) '/) | |
755 (if (math-units-in-expr-p (nth 2 expr) nil) | |
756 'wrong | |
757 (math-single-units-in-expr-p (nth 1 expr)))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
758 (t 'wrong))) |
40785 | 759 |
760 (defun math-check-unit-name (v) | |
761 (and (eq (car-safe v) 'var) | |
762 (or (assq (nth 1 v) (or math-units-table (math-build-units-table))) | |
763 (let ((name (symbol-name (nth 1 v)))) | |
764 (and (> (length name) 1) | |
765 (assq (aref name 0) math-unit-prefixes) | |
766 (or (assq (intern (substring name 1)) math-units-table) | |
767 (and (eq (aref name 0) ?M) | |
768 (> (length name) 3) | |
769 (eq (aref name 1) ?e) | |
770 (eq (aref name 2) ?g) | |
771 (assq (intern (substring name 3)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
772 math-units-table)))))))) |
40785 | 773 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
774 ;; The variable math-which-standard is local to math-to-standard-units, |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
775 ;; but is used by math-to-standard-rec, which is called by |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
776 ;; math-to-standard-units. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
777 (defvar math-which-standard) |
40785 | 778 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
779 (defun math-to-standard-units (expr math-which-standard) |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
780 (math-to-standard-rec expr)) |
40785 | 781 |
782 (defun math-to-standard-rec (expr) | |
783 (if (eq (car-safe expr) 'var) | |
784 (let ((u (math-check-unit-name expr)) | |
785 (base (nth 1 expr))) | |
786 (if u | |
787 (progn | |
788 (if (nth 1 u) | |
789 (setq expr (math-to-standard-rec (nth 1 u))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
790 (let ((st (assq (car u) math-which-standard))) |
40785 | 791 (if st |
792 (setq expr (nth 1 st)) | |
793 (setq expr (list 'var (car u) | |
794 (intern (concat "var-" | |
795 (symbol-name | |
796 (car u))))))))) | |
797 (or (null u) | |
798 (eq base (car u)) | |
799 (setq expr (list '* | |
800 (nth 1 (assq (aref (symbol-name base) 0) | |
801 math-unit-prefixes)) | |
802 expr))) | |
803 expr) | |
804 (if (eq base 'pi) | |
805 (math-pi) | |
806 expr))) | |
807 (if (Math-primp expr) | |
808 expr | |
809 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
810 (mapcar 'math-to-standard-rec (cdr expr)))))) |
40785 | 811 |
812 (defun math-apply-units (expr units ulist &optional pure) | |
813 (if ulist | |
814 (let ((new 0) | |
815 value) | |
816 (setq expr (math-simplify-units expr)) | |
817 (or (math-numberp expr) | |
818 (error "Incompatible units")) | |
819 (while (cdr ulist) | |
820 (setq value (math-div expr (nth 1 (car ulist))) | |
821 value (math-floor (let ((calc-internal-prec | |
822 (1- calc-internal-prec))) | |
823 (math-normalize value))) | |
824 new (math-add new (math-mul value (car (car ulist)))) | |
825 expr (math-sub expr (math-mul value (nth 1 (car ulist)))) | |
826 ulist (cdr ulist))) | |
827 (math-add new (math-mul (math-div expr (nth 1 (car ulist))) | |
828 (car (car ulist))))) | |
829 (math-simplify-units (if pure | |
830 expr | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
831 (list '* expr units))))) |
40785 | 832 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
833 (defvar math-decompose-units-cache nil) |
40785 | 834 (defun math-decompose-units (units) |
835 (let ((u (math-check-unit-name units))) | |
836 (and u (eq (car-safe (nth 1 u)) '+) | |
837 (setq units (nth 1 u)))) | |
838 (setq units (calcFunc-expand units)) | |
839 (and (eq (car-safe units) '+) | |
840 (let ((entry (list units calc-internal-prec calc-prefer-frac))) | |
841 (or (equal entry (car math-decompose-units-cache)) | |
842 (let ((ulist nil) | |
843 (utemp units) | |
844 qty unit) | |
845 (while (eq (car-safe utemp) '+) | |
846 (setq ulist (cons (math-decompose-unit-part (nth 2 utemp)) | |
847 ulist) | |
848 utemp (nth 1 utemp))) | |
849 (setq ulist (cons (math-decompose-unit-part utemp) ulist) | |
850 utemp ulist) | |
851 (while (setq utemp (cdr utemp)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
852 (unless (equal (nth 2 (car utemp)) (nth 2 (car ulist))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
853 (error "Inconsistent units in sum"))) |
40785 | 854 (setq math-decompose-units-cache |
855 (cons entry | |
856 (sort ulist | |
857 (function | |
858 (lambda (x y) | |
859 (not (Math-lessp (nth 1 x) | |
860 (nth 1 y)))))))))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
861 (cdr math-decompose-units-cache)))) |
40785 | 862 |
863 (defun math-decompose-unit-part (unit) | |
864 (cons unit | |
865 (math-is-multiple (math-simplify-units (math-to-standard-units | |
866 unit nil)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
867 t))) |
40785 | 868 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
869 ;; The variable math-fcu-u is local to math-find-compatible-unit, |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
870 ;; but is used by math-find-compatible-rec which is called by |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
871 ;; math-find-compatible-unit. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
872 (defvar math-fcu-u) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
873 |
40785 | 874 (defun math-find-compatible-unit (expr unit) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
875 (let ((math-fcu-u (math-check-unit-name unit))) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
876 (if math-fcu-u |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
877 (math-find-compatible-unit-rec expr 1)))) |
40785 | 878 |
879 (defun math-find-compatible-unit-rec (expr pow) | |
880 (cond ((eq (car-safe expr) '*) | |
881 (or (math-find-compatible-unit-rec (nth 1 expr) pow) | |
882 (math-find-compatible-unit-rec (nth 2 expr) pow))) | |
883 ((eq (car-safe expr) '/) | |
884 (or (math-find-compatible-unit-rec (nth 1 expr) pow) | |
885 (math-find-compatible-unit-rec (nth 2 expr) (- pow)))) | |
886 ((and (eq (car-safe expr) '^) | |
887 (integerp (nth 2 expr))) | |
888 (math-find-compatible-unit-rec (nth 1 expr) (* pow (nth 2 expr)))) | |
889 (t | |
890 (let ((u2 (math-check-unit-name expr))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
891 (if (equal (nth 4 math-fcu-u) (nth 4 u2)) |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
892 (cons expr pow)))))) |
40785 | 893 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
894 ;; The variables math-cu-new-units and math-cu-pure are local to |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
895 ;; math-convert-units, but are used by math-convert-units-rec, |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
896 ;; which is called by math-convert-units. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
897 (defvar math-cu-new-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
898 (defvar math-cu-pure) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
899 |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
900 (defun math-convert-units (expr math-cu-new-units &optional math-cu-pure) |
40785 | 901 (math-with-extra-prec 2 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
902 (let ((compat (and (not math-cu-pure) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
903 (math-find-compatible-unit expr math-cu-new-units))) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
904 (math-cu-unit-list nil) |
40785 | 905 (math-combining-units nil)) |
906 (if compat | |
907 (math-simplify-units | |
908 (math-mul (math-mul (math-simplify-units | |
909 (math-div expr (math-pow (car compat) | |
910 (cdr compat)))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
911 (math-pow math-cu-new-units (cdr compat))) |
40785 | 912 (math-simplify-units |
913 (math-to-standard-units | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
914 (math-pow (math-div (car compat) math-cu-new-units) |
40785 | 915 (cdr compat)) |
916 nil)))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
917 (when (setq math-cu-unit-list (math-decompose-units math-cu-new-units)) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
918 (setq math-cu-new-units (nth 2 (car math-cu-unit-list)))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
919 (when (eq (car-safe expr) '+) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
920 (setq expr (math-simplify-units expr))) |
40785 | 921 (if (math-units-in-expr-p expr t) |
922 (math-convert-units-rec expr) | |
923 (math-apply-units (math-to-standard-units | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
924 (list '/ expr math-cu-new-units) nil) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
925 math-cu-new-units math-cu-unit-list math-cu-pure)))))) |
40785 | 926 |
927 (defun math-convert-units-rec (expr) | |
928 (if (math-units-in-expr-p expr nil) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
929 (math-apply-units (math-to-standard-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
930 (list '/ expr math-cu-new-units) nil) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
931 math-cu-new-units math-cu-unit-list math-cu-pure) |
40785 | 932 (if (Math-primp expr) |
933 expr | |
934 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
935 (mapcar 'math-convert-units-rec (cdr expr)))))) |
40785 | 936 |
937 (defun math-convert-temperature (expr old new &optional pure) | |
938 (let* ((units (math-single-units-in-expr-p expr)) | |
939 (uold (if old | |
940 (if (or (null units) | |
941 (equal (nth 1 old) (car units))) | |
942 (math-check-unit-name old) | |
943 (error "Inconsistent temperature units")) | |
944 units)) | |
945 (unew (math-check-unit-name new))) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
946 (unless (and (consp unew) (nth 3 unew)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
947 (error "Not a valid temperature unit")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
948 (unless (and (consp uold) (nth 3 uold)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
949 (error "Not a pure temperature expression")) |
40785 | 950 (let ((v (car uold))) |
951 (setq expr (list '/ expr (list 'var v | |
952 (intern (concat "var-" | |
953 (symbol-name v))))))) | |
954 (or (eq (nth 3 uold) (nth 3 unew)) | |
955 (cond ((eq (nth 3 uold) 'K) | |
956 (setq expr (list '- expr '(float 27315 -2))) | |
957 (if (eq (nth 3 unew) 'F) | |
958 (setq expr (list '+ (list '* expr '(frac 9 5)) 32)))) | |
959 ((eq (nth 3 uold) 'C) | |
960 (if (eq (nth 3 unew) 'F) | |
961 (setq expr (list '+ (list '* expr '(frac 9 5)) 32)) | |
962 (setq expr (list '+ expr '(float 27315 -2))))) | |
963 (t | |
964 (setq expr (list '* (list '- expr 32) '(frac 5 9))) | |
965 (if (eq (nth 3 unew) 'K) | |
966 (setq expr (list '+ expr '(float 27315 -2))))))) | |
967 (if pure | |
968 expr | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
969 (list '* expr new)))) |
40785 | 970 |
971 | |
972 | |
973 (defun math-simplify-units (a) | |
974 (let ((math-simplifying-units t) | |
975 (calc-matrix-mode 'scalar)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
976 (math-simplify a))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
977 (defalias 'calcFunc-usimplify 'math-simplify-units) |
40785 | 978 |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
979 ;; The function created by math-defsimplify uses the variable |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
980 ;; math-simplify-expr, and so is used by functions in math-defsimplify |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
981 (defvar math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
982 |
40785 | 983 (math-defsimplify (+ -) |
984 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
985 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
986 (let* ((units (math-extract-units (nth 1 math-simplify-expr))) |
40785 | 987 (ratio (math-simplify (math-to-standard-units |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
988 (list '/ (nth 2 math-simplify-expr) units) nil)))) |
40785 | 989 (if (math-units-in-expr-p ratio nil) |
990 (progn | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
991 (calc-record-why "*Inconsistent units" math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
992 math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
993 (list '* (math-add (math-remove-units (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
994 (if (eq (car math-simplify-expr) '-) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
995 (math-neg ratio) ratio)) |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
996 units))))) |
40785 | 997 |
998 (math-defsimplify * | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
999 (math-simplify-units-prod)) |
40785 | 1000 |
1001 (defun math-simplify-units-prod () | |
1002 (and math-simplifying-units | |
1003 calc-autorange-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1004 (Math-realp (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1005 (let* ((num (math-float (nth 1 math-simplify-expr))) |
40785 | 1006 (xpon (calcFunc-xpon num)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1007 (unitp (cdr (cdr math-simplify-expr))) |
40785 | 1008 (unit (car unitp)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1009 (pow (if (eq (car math-simplify-expr) '*) 1 -1)) |
40785 | 1010 u) |
1011 (and (eq (car-safe unit) '*) | |
1012 (setq unitp (cdr unit) | |
1013 unit (car unitp))) | |
1014 (and (eq (car-safe unit) '^) | |
1015 (integerp (nth 2 unit)) | |
1016 (setq pow (* pow (nth 2 unit)) | |
1017 unitp (cdr unit) | |
1018 unit (car unitp))) | |
1019 (and (setq u (math-check-unit-name unit)) | |
1020 (integerp xpon) | |
1021 (or (< xpon 0) | |
1022 (>= xpon (if (eq (car u) 'm) 1 3))) | |
1023 (let* ((uxpon 0) | |
1024 (pref (if (< pow 0) | |
1025 (reverse math-unit-prefixes) | |
1026 math-unit-prefixes)) | |
1027 (p pref) | |
1028 pxpon pname) | |
1029 (or (eq (car u) (nth 1 unit)) | |
1030 (setq uxpon (* pow | |
1031 (nth 2 (nth 1 (assq | |
1032 (aref (symbol-name | |
1033 (nth 1 unit)) 0) | |
1034 math-unit-prefixes)))))) | |
1035 (setq xpon (+ xpon uxpon)) | |
1036 (while (and p | |
1037 (or (memq (car (car p)) '(?d ?D ?h ?H)) | |
1038 (and (eq (car (car p)) ?c) | |
1039 (not (eq (car u) 'm))) | |
1040 (< xpon (setq pxpon (* (nth 2 (nth 1 (car p))) | |
1041 pow))) | |
1042 (progn | |
1043 (setq pname (math-build-var-name | |
1044 (if (eq (car (car p)) 0) | |
1045 (car u) | |
1046 (concat (char-to-string | |
1047 (car (car p))) | |
1048 (symbol-name | |
1049 (car u)))))) | |
1050 (and (/= (car (car p)) 0) | |
1051 (assq (nth 1 pname) | |
1052 math-units-table))))) | |
1053 (setq p (cdr p))) | |
1054 (and p | |
1055 (/= pxpon uxpon) | |
1056 (or (not (eq p pref)) | |
1057 (< xpon (+ pxpon (* (math-abs pow) 3)))) | |
1058 (progn | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1059 (setcar (cdr math-simplify-expr) |
40785 | 1060 (let ((calc-prefer-frac nil)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1061 (calcFunc-scf (nth 1 math-simplify-expr) |
40785 | 1062 (- uxpon pxpon)))) |
1063 (setcar unitp pname) | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1064 math-simplify-expr))))))) |
40785 | 1065 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1066 (defvar math-try-cancel-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1067 |
40785 | 1068 (math-defsimplify / |
1069 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1070 (let ((np (cdr math-simplify-expr)) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1071 (math-try-cancel-units 0) |
40785 | 1072 n nn) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1073 (setq n (if (eq (car-safe (nth 2 math-simplify-expr)) '*) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1074 (cdr (nth 2 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1075 (nthcdr 2 math-simplify-expr))) |
40785 | 1076 (if (math-realp (car n)) |
1077 (progn | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1078 (setcar (cdr math-simplify-expr) (math-mul (nth 1 math-simplify-expr) |
40785 | 1079 (let ((calc-prefer-frac nil)) |
1080 (math-div 1 (car n))))) | |
1081 (setcar n 1))) | |
1082 (while (eq (car-safe (setq n (car np))) '*) | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1083 (math-simplify-units-divisor (cdr n) (cdr (cdr math-simplify-expr))) |
40785 | 1084 (setq np (cdr (cdr n)))) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1085 (math-simplify-units-divisor np (cdr (cdr math-simplify-expr))) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1086 (if (eq math-try-cancel-units 0) |
40785 | 1087 (let* ((math-simplifying-units nil) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1088 (base (math-simplify |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1089 (math-to-standard-units math-simplify-expr nil)))) |
40785 | 1090 (if (Math-numberp base) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1091 (setq math-simplify-expr base)))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1092 (if (eq (car-safe math-simplify-expr) '/) |
40785 | 1093 (math-simplify-units-prod)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1094 math-simplify-expr))) |
40785 | 1095 |
1096 (defun math-simplify-units-divisor (np dp) | |
1097 (let ((n (car np)) | |
1098 d dd temp) | |
1099 (while (eq (car-safe (setq d (car dp))) '*) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1100 (when (setq temp (math-simplify-units-quotient n (nth 1 d))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1101 (setcar np (setq n temp)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1102 (setcar (cdr d) 1)) |
40785 | 1103 (setq dp (cdr (cdr d)))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1104 (when (setq temp (math-simplify-units-quotient n d)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1105 (setcar np (setq n temp)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1106 (setcar dp 1)))) |
40785 | 1107 |
1108 ;; Simplify, e.g., "in / cm" to "2.54" in a units expression. | |
1109 (defun math-simplify-units-quotient (n d) | |
1110 (let ((pow1 1) | |
1111 (pow2 1)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1112 (when (and (eq (car-safe n) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1113 (integerp (nth 2 n))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1114 (setq pow1 (nth 2 n) n (nth 1 n))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1115 (when (and (eq (car-safe d) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1116 (integerp (nth 2 d))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1117 (setq pow2 (nth 2 d) d (nth 1 d))) |
40785 | 1118 (let ((un (math-check-unit-name n)) |
1119 (ud (math-check-unit-name d))) | |
1120 (and un ud | |
1121 (if (and (equal (nth 4 un) (nth 4 ud)) | |
1122 (eq pow1 pow2)) | |
1123 (math-to-standard-units (list '/ n d) nil) | |
1124 (let (ud1) | |
1125 (setq un (nth 4 un) | |
1126 ud (nth 4 ud)) | |
1127 (while un | |
1128 (setq ud1 ud) | |
1129 (while ud1 | |
1130 (and (eq (car (car un)) (car (car ud1))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1131 (setq math-try-cancel-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1132 (+ math-try-cancel-units |
40785 | 1133 (- (* (cdr (car un)) pow1) |
1134 (* (cdr (car ud)) pow2))))) | |
1135 (setq ud1 (cdr ud1))) | |
1136 (setq un (cdr un))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1137 nil)))))) |
40785 | 1138 |
1139 (math-defsimplify ^ | |
1140 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1141 (math-realp (nth 2 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1142 (if (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1143 (list (car (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1144 (list '^ (nth 1 (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1145 (nth 2 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1146 (list '^ (nth 2 (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1147 (nth 2 math-simplify-expr))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1148 (math-simplify-units-pow (nth 1 math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1149 (nth 2 math-simplify-expr))))) |
40785 | 1150 |
1151 (math-defsimplify calcFunc-sqrt | |
1152 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1153 (if (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1154 (list (car (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1155 (list 'calcFunc-sqrt (nth 1 (nth 1 math-simplify-expr))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1156 (list 'calcFunc-sqrt (nth 2 (nth 1 math-simplify-expr)))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1157 (math-simplify-units-pow (nth 1 math-simplify-expr) '(frac 1 2))))) |
40785 | 1158 |
1159 (math-defsimplify (calcFunc-floor | |
1160 calcFunc-ceil | |
1161 calcFunc-round | |
1162 calcFunc-rounde | |
1163 calcFunc-roundu | |
1164 calcFunc-trunc | |
1165 calcFunc-float | |
1166 calcFunc-frac | |
1167 calcFunc-abs | |
1168 calcFunc-clean) | |
1169 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1170 (= (length math-simplify-expr) 2) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1171 (if (math-only-units-in-expr-p (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1172 (nth 1 math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1173 (if (and (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
40785 | 1174 (or (math-only-units-in-expr-p |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1175 (nth 1 (nth 1 math-simplify-expr))) |
40785 | 1176 (math-only-units-in-expr-p |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1177 (nth 2 (nth 1 math-simplify-expr))))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1178 (list (car (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1179 (cons (car math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1180 (cons (nth 1 (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1181 (cdr (cdr math-simplify-expr)))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1182 (cons (car math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1183 (cons (nth 2 (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1184 (cdr (cdr math-simplify-expr))))))))) |
40785 | 1185 |
1186 (defun math-simplify-units-pow (a pow) | |
1187 (if (and (eq (car-safe a) '^) | |
1188 (math-check-unit-name (nth 1 a)) | |
1189 (math-realp (nth 2 a))) | |
1190 (list '^ (nth 1 a) (math-mul pow (nth 2 a))) | |
1191 (let* ((u (math-check-unit-name a)) | |
1192 (pf (math-to-simple-fraction pow)) | |
1193 (d (and (eq (car-safe pf) 'frac) (nth 2 pf)))) | |
1194 (and u d | |
1195 (math-units-are-multiple u d) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1196 (list '^ (math-to-standard-units a nil) pow))))) |
40785 | 1197 |
1198 | |
1199 (defun math-units-are-multiple (u n) | |
1200 (setq u (nth 4 u)) | |
1201 (while (and u (= (% (cdr (car u)) n) 0)) | |
1202 (setq u (cdr u))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1203 (null u)) |
40785 | 1204 |
1205 (math-defsimplify calcFunc-sin | |
1206 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1207 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
40785 | 1208 (let ((rad (math-simplify-units |
1209 (math-evaluate-expr | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1210 (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
40785 | 1211 (calc-angle-mode 'rad)) |
1212 (and (eq (car-safe rad) '*) | |
1213 (math-realp (nth 1 rad)) | |
1214 (eq (car-safe (nth 2 rad)) 'var) | |
1215 (eq (nth 1 (nth 2 rad)) 'rad) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1216 (list 'calcFunc-sin (nth 1 rad)))))) |
40785 | 1217 |
1218 (math-defsimplify calcFunc-cos | |
1219 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1220 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
40785 | 1221 (let ((rad (math-simplify-units |
1222 (math-evaluate-expr | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1223 (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
40785 | 1224 (calc-angle-mode 'rad)) |
1225 (and (eq (car-safe rad) '*) | |
1226 (math-realp (nth 1 rad)) | |
1227 (eq (car-safe (nth 2 rad)) 'var) | |
1228 (eq (nth 1 (nth 2 rad)) 'rad) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1229 (list 'calcFunc-cos (nth 1 rad)))))) |
40785 | 1230 |
1231 (math-defsimplify calcFunc-tan | |
1232 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1233 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
40785 | 1234 (let ((rad (math-simplify-units |
1235 (math-evaluate-expr | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1236 (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
40785 | 1237 (calc-angle-mode 'rad)) |
1238 (and (eq (car-safe rad) '*) | |
1239 (math-realp (nth 1 rad)) | |
1240 (eq (car-safe (nth 2 rad)) 'var) | |
1241 (eq (nth 1 (nth 2 rad)) 'rad) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1242 (list 'calcFunc-tan (nth 1 rad)))))) |
40785 | 1243 |
1244 | |
1245 (defun math-remove-units (expr) | |
1246 (if (math-check-unit-name expr) | |
1247 1 | |
1248 (if (Math-primp expr) | |
1249 expr | |
1250 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1251 (mapcar 'math-remove-units (cdr expr)))))) |
40785 | 1252 |
1253 (defun math-extract-units (expr) | |
1254 (if (memq (car-safe expr) '(* /)) | |
1255 (cons (car expr) | |
1256 (mapcar 'math-extract-units (cdr expr))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1257 (if (math-check-unit-name expr) expr 1))) |
40785 | 1258 |
1259 (defun math-build-units-table-buffer (enter-buffer) | |
1260 (if (not (and math-units-table math-units-table-buffer-valid | |
1261 (get-buffer "*Units Table*"))) | |
1262 (let ((buf (get-buffer-create "*Units Table*")) | |
1263 (uptr (math-build-units-table)) | |
1264 (calc-language (if (eq calc-language 'big) nil calc-language)) | |
1265 (calc-float-format '(float 0)) | |
1266 (calc-group-digits nil) | |
1267 (calc-number-radix 10) | |
1268 (calc-point-char ".") | |
1269 (std nil) | |
1270 u name shadowed) | |
1271 (save-excursion | |
1272 (message "Formatting units table...") | |
1273 (set-buffer buf) | |
1274 (setq buffer-read-only nil) | |
1275 (erase-buffer) | |
1276 (insert "Calculator Units Table:\n\n") | |
1277 (insert "Unit Type Definition Description\n\n") | |
1278 (while uptr | |
1279 (setq u (car uptr) | |
1280 name (nth 2 u)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1281 (when (eq (car u) 'm) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1282 (setq std t)) |
40785 | 1283 (setq shadowed (and std (assq (car u) math-additional-units))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1284 (when (and name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1285 (> (length name) 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1286 (eq (aref name 0) ?\*)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1287 (unless (eq uptr math-units-table) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1288 (insert "\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1289 (setq name (substring name 1))) |
40785 | 1290 (insert " ") |
1291 (and shadowed (insert "(")) | |
1292 (insert (symbol-name (car u))) | |
1293 (and shadowed (insert ")")) | |
1294 (if (nth 3 u) | |
1295 (progn | |
1296 (indent-to 10) | |
1297 (insert (symbol-name (nth 3 u)))) | |
1298 (or std | |
1299 (progn | |
1300 (indent-to 10) | |
1301 (insert "U")))) | |
1302 (indent-to 14) | |
1303 (and shadowed (insert "(")) | |
1304 (if (nth 1 u) | |
1305 (insert (math-format-value (nth 1 u) 80)) | |
1306 (insert (symbol-name (car u)))) | |
1307 (and shadowed (insert ")")) | |
1308 (indent-to 41) | |
1309 (insert " ") | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1310 (when name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1311 (insert name)) |
40785 | 1312 (if shadowed |
1313 (insert " (redefined above)") | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1314 (unless (nth 1 u) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1315 (insert " (base unit)"))) |
40785 | 1316 (insert "\n") |
1317 (setq uptr (cdr uptr))) | |
1318 (insert "\n\nUnit Prefix Table:\n\n") | |
1319 (setq uptr math-unit-prefixes) | |
1320 (while uptr | |
1321 (setq u (car uptr)) | |
1322 (insert " " (char-to-string (car u))) | |
1323 (if (equal (nth 1 u) (nth 1 (nth 1 uptr))) | |
1324 (insert " " (char-to-string (car (car (setq uptr (cdr uptr))))) | |
1325 " ") | |
1326 (insert " ")) | |
1327 (insert "10^" (int-to-string (nth 2 (nth 1 u)))) | |
1328 (indent-to 15) | |
1329 (insert " " (nth 2 u) "\n") | |
1330 (while (eq (car (car (setq uptr (cdr uptr)))) 0))) | |
1331 (insert "\n") | |
1332 (setq buffer-read-only t) | |
1333 (message "Formatting units table...done")) | |
1334 (setq math-units-table-buffer-valid t) | |
1335 (let ((oldbuf (current-buffer))) | |
1336 (set-buffer buf) | |
1337 (goto-char (point-min)) | |
1338 (set-buffer oldbuf)) | |
1339 (if enter-buffer | |
1340 (pop-to-buffer buf) | |
1341 (display-buffer buf))) | |
1342 (if enter-buffer | |
1343 (pop-to-buffer (get-buffer "*Units Table*")) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1344 (display-buffer (get-buffer "*Units Table*"))))) |
40785 | 1345 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1346 ;; Local Variables: |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1347 ;; coding: iso-latin-1 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1348 ;; End: |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1349 |
52401 | 1350 ;;; arch-tag: e993314f-3adc-4191-be61-4ef8874881c4 |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1351 ;;; calc-units.el ends here |