annotate lisp/calc/calc-units.el @ 108590:c84578d13e42

calc-aent.el (math-read-token, math-find-user-tokens): calc-lang.el (math-read-big-rec, math-lang-read-symbol) (math-compose-tex-func): calccomp.el (math-compose-expr): calc-ext.el (math-format-flat-expr-fancy): calc-store.el (calc-read-var-name): calc-units.el (calc-explain-units-rec): Allow Greek letters. calc.el (var-¦Ð, var-¦Õ, var-¦Ã): New variables. calc-aent.el (math-read-replacement-list): Add "micro" symbol. calc-units.el (math-unit-prefixes): Add mu for micro. (math-standard-units): Add units.
author Jay Belanger <jay.p.belanger@gmail.com>
date Fri, 14 May 2010 23:50:25 -0500
parents 1d1d5d9bd884
children d150a25a0eb9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
64325
1db49616ce05 Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64163
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106145
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
5
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
6 ;; Author: David Gillespie <daveg@synaptics.com>
77465
1154f082efd9 Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 76595
diff changeset
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
19 ;; GNU General Public License for more details.
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
20
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
24 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
26 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; This file is autoloaded from calc-ext.el.
58677
5ef7cf7f3b8f Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58511
diff changeset
29
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-macs)
59394
18e7205127f0 Make sure the proper macro definitions are available when compiling.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58677
diff changeset
32 (eval-when-compile
18e7205127f0 Make sure the proper macro definitions are available when compiling.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58677
diff changeset
33 (require 'calc-alg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 ;;; Units operations.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37 ;;; Units table last updated 9-Jan-91 by Ulrich Mueller (ulm@vsnhd1.cern.ch)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 ;;; with some additions by Przemek Klosowski (przemek@rrdstrad.nist.gov)
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
39 ;;; Updated April 2002 by Jochen Küpper
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
40
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
41 ;;; Updated August 2007, using
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
42 ;;; CODATA (http://physics.nist.gov/cuu/Constants/index.html)
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
43 ;;; NIST (http://physics.nist.gov/Pubs/SP811/appenB9.html)
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
44 ;;; ESUWM (Encyclopaedia of Scientific Units, Weights and
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
45 ;;; Measures, by François Cardarelli)
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
46 ;;; All conversions are exact unless otherwise noted.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (defvar math-standard-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 '( ;; Length
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
50 ( m nil "*Meter" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
51 ( in "254*10^(-2) cm" "Inch" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
52 "2.54 cm")
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
53 ( ft "12 in" "Foot")
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
54 ( yd "3 ft" "Yard" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
55 ( mi "5280 ft" "Mile" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
56 ( au "149597870691. m" "Astronomical Unit" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
57 "149597870691 m (*)")
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
58 ;; (approx) NASA JPL (http://neo.jpl.nasa.gov/glossary/au.html)
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
59 ( lyr "c yr" "Light Year" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
60 ( pc "3.0856775854*10^16 m" "Parsec" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
61 "3.0856775854 10^16 m (*)") ;; (approx) ESUWM
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
62 ( nmi "1852 m" "Nautical Mile" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
63 ( fath "6 ft" "Fathom" )
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
64 ( fur "660 ft" "Furlong")
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
65 ( mu "1 um" "Micron" )
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
66 ( mil "(1/1000) in" "Mil" )
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
67 ( point "(1/72) in" "Point (1/72 inch)" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
68 ( Ang "10^(-10) m" "Angstrom" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
69 ( mfi "mi+ft+in" "Miles + feet + inches" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
70 ;; TeX lengths
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
71 ( texpt "(100/7227) in" "Point (TeX conventions)" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
72 ( texpc "12 texpt" "Pica" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
73 ( texbp "point" "Big point (TeX conventions)" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
74 ( texdd "(1238/1157) texpt" "Didot point" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
75 ( texcc "12 texdd" "Cicero" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
76 ( texsp "(1/65536) texpt" "Scaled TeX point" )
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
77
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
78 ;; Area
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
79 ( hect "10000 m^2" "*Hectare" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
80 ( a "100 m^2" "Are")
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
81 ( acre "(1/640) mi^2" "Acre" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
82 ( b "10^(-28) m^2" "Barn" )
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
83
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
84 ;; Volume
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
85 ( L "10^(-3) m^3" "*Liter" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
86 ( l "L" "Liter" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
87 ( gal "4 qt" "US Gallon" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
88 ( qt "2 pt" "Quart" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
89 ( pt "2 cup" "Pint" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
90 ( cup "8 ozfl" "Cup" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
91 ( ozfl "2 tbsp" "Fluid Ounce" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
92 ( floz "2 tbsp" "Fluid Ounce" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
93 ( tbsp "3 tsp" "Tablespoon" )
82436
396a03499dc0 (math-standard-units): Give exact conversion for tsp.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82390
diff changeset
94 ;; ESUWM defines a US gallon as 231 in^3.
396a03499dc0 (math-standard-units): Give exact conversion for tsp.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82390
diff changeset
95 ;; That gives the following exact value for tsp.
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
96 ( tsp "492892159375*10^(-11) ml" "Teaspoon" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
97 "4.92892159375 ml")
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
98 ( vol "tsp+tbsp+ozfl+cup+pt+qt+gal" "Gallons + ... + teaspoons" nil
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
99 "tsp+tbsp+ozfl+cup+pt+qt+gal")
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
100 ( galC "galUK" "Canadian Gallon" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
101 ( galUK "454609*10^(-5) L" "UK Gallon" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
102 "4.54609 L") ;; NIST
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
103
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
104 ;; Time
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
105 ( s nil "*Second" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
106 ( sec "s" "Second" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
107 ( min "60 s" "Minute" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
108 ( hr "60 min" "Hour" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
109 ( day "24 hr" "Day" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
110 ( wk "7 day" "Week" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
111 ( hms "wk+day+hr+min+s" "Hours, minutes, seconds" )
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
112 ( yr "36525*10^(-2) day" "Year (Julian)" nil
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
113 "365.25 day")
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
114 ( Hz "1/s" "Hertz" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
116 ;; Speed
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
117 ( mph "mi/hr" "*Miles per hour" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
118 ( kph "km/hr" "Kilometers per hour" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
119 ( knot "nmi/hr" "Knot" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
120 ( c "299792458 m/s" "Speed of light" ) ;;; CODATA
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
121
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
122 ;; Acceleration
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
123 ( ga "980665*10^(-5) m/s^2" "*\"g\" acceleration" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
124 "9.80665 m / s^2") ;; CODATA
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
126 ;; Mass
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
127 ( g nil "*Gram" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
128 ( lb "16 oz" "Pound (mass)" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
129 ( oz "28349523125*10^(-9) g" "Ounce (mass)" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
130 "28.349523125 g") ;; ESUWM
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
131 ( ton "2000 lb" "Ton" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
132 ( tpo "ton+lb+oz" "Tons + pounds + ounces (mass)" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
133 ( t "1000 kg" "Metric ton" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
134 ( tonUK "10160469088*10^(-7) kg" "UK ton" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
135 "1016.0469088 kg") ;; ESUWM
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
136 ( lbt "12 ozt" "Troy pound" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
137 ( ozt "311034768*10^(-7) g" "Troy ounce" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
138 "31.10347680 g") ;; ESUWM, 1/12 exact value for lbt
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
139 ( ct "(2/10) g" "Carat" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
140 "0.2 g") ;; ESUWM
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
141 ( u "1.660538782*10^(-27) kg" "Unified atomic mass" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
142 "1.660538782 10^-27 kg (*)");;(approx) CODATA
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
144 ;; Force
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
145 ( N "m kg/s^2" "*Newton" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
146 ( dyn "10^(-5) N" "Dyne" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
147 ( gf "ga g" "Gram (force)" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
148 ( lbf "ga lb" "Pound (force)" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
149 ( kip "1000 lbf" "Kilopound (force)" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
150 ( pdl "138254954376*10^(-12) N" "Poundal" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
151 "0.138254954376 N") ;; ESUWM
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
153 ;; Energy
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
154 ( J "N m" "*Joule" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
155 ( erg "10^(-7) J" "Erg" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
156 ( cal "41868*10^(-4) J" "International Table Calorie" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
157 "4.1868 J") ;; NIST
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
158 ( calth "4184*10^(-3) J" "Thermochemical Calorie" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
159 "4.184 J") ;; NIST
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
160 ( Cal "1000 cal" "Large Calorie")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
161 ( Btu "105505585262*10^(-8) J" "International Table Btu" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
162 "1055.05585262 J") ;; ESUWM
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
163 ( eV "ech V" "Electron volt" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
164 ( ev "eV" "Electron volt" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
165 ( therm "105506000 J" "EEC therm" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
166 ( invcm "h c/cm" "Energy in inverse centimeters" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
167 ( Kayser "invcm" "Kayser (inverse centimeter energy)" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
168 ( men "100/invcm" "Inverse energy in meters" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
169 ( Hzen "h Hz" "Energy in Hertz")
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
170 ( Ken "k K" "Energy in Kelvins")
61412
4291a3412879 (math-standard-units): Redefine Watt hour as W*hr.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60082
diff changeset
171 ( Wh "W hr" "Watt hour")
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
172 ( Ws "W s" "Watt second")
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
174 ;; Power
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
175 ( W "J/s" "*Watt" )
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
176 ( hp "550 ft lbf/s" "Horsepower") ;;ESUWM
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
177 ( hpm "75 m kgf/s" "Metric Horsepower") ;;ESUWM
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
179 ;; Temperature
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
180 ( K nil "*Degree Kelvin" K )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
181 ( dK "K" "Degree Kelvin" K )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
182 ( degK "K" "Degree Kelvin" K )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
183 ( dC "K" "Degree Celsius" C )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
184 ( degC "K" "Degree Celsius" C )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
185 ( dF "(5/9) K" "Degree Fahrenheit" F )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
186 ( degF "(5/9) K" "Degree Fahrenheit" F )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
188 ;; Pressure
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
189 ( Pa "N/m^2" "*Pascal" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
190 ( bar "10^5 Pa" "Bar" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
191 ( atm "101325 Pa" "Standard atmosphere" ) ;; CODATA
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
192 ( Torr "(1/760) atm" "Torr")
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
193 ( mHg "1000 Torr" "Meter of mercury" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
194 ( inHg "254*10^(-1) mmHg" "Inch of mercury" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
195 "25.4 mmHg")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
196 ( inH2O "2.490889*10^2 Pa" "Inch of water" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
197 "2.490889 10^2 Pa (*)") ;;(approx) NIST
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
198 ( psi "lbf/in^2" "Pounds per square inch" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
200 ;; Viscosity
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
201 ( P "(1/10) Pa s" "*Poise" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
202 ( St "10^(-4) m^2/s" "Stokes" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
204 ;; Electromagnetism
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
205 ( A nil "*Ampere" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
206 ( C "A s" "Coulomb" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
207 ( Fdy "ech Nav" "Faraday" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
208 ( e "ech" "Elementary charge" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
209 ( ech "1.602176487*10^(-19) C" "Elementary charge" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
210 "1.602176487 10^-19 C (*)") ;;(approx) CODATA
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
211 ( V "W/A" "Volt" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
212 ( ohm "V/A" "Ohm" )
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
213 ( Ω "ohm" "Ohm" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
214 ( mho "A/V" "Mho" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
215 ( S "A/V" "Siemens" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
216 ( F "C/V" "Farad" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
217 ( H "Wb/A" "Henry" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
218 ( T "Wb/m^2" "Tesla" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
219 ( Gs "10^(-4) T" "Gauss" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
220 ( Wb "V s" "Weber" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
222 ;; Luminous intensity
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
223 ( cd nil "*Candela" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
224 ( sb "10000 cd/m^2" "Stilb" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
225 ( lm "cd sr" "Lumen" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
226 ( lx "lm/m^2" "Lux" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
227 ( ph "10000 lx" "Phot" )
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
228 ( fc "lm/ft^2" "Footcandle") ;; ESUWM
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
229 ( lam "10000 lm/m^2" "Lambert" )
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
230 ( flam "(1/pi) cd/ft^2" "Footlambert") ;; ESUWM
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
232 ;; Radioactivity
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
233 ( Bq "1/s" "*Becquerel" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
234 ( Ci "37*10^9 Bq" "Curie" ) ;; ESUWM
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
235 ( Gy "J/kg" "Gray" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
236 ( Sv "Gy" "Sievert" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
237 ( R "258*10^(-6) C/kg" "Roentgen" ) ;; NIST
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
238 ( rd "(1/100) Gy" "Rad" )
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
239 ( rem "rd" "Rem" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
240
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
241 ;; Amount of substance
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
242 ( mol nil "*Mole" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
243
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
244 ;; Plane angle
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
245 ( rad nil "*Radian" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
246 ( circ "2 pi rad" "Full circle" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
247 ( rev "circ" "Full revolution" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
248 ( deg "circ/360" "Degree" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
249 ( arcmin "deg/60" "Arc minute" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
250 ( arcsec "arcmin/60" "Arc second" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
251 ( grad "circ/400" "Grade" )
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
252 ( rpm "rev/min" "Revolutions per minute" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253
45291
01f46f9c1fa0 (math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents: 41269
diff changeset
254 ;; Solid angle
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
255 ( sr nil "*Steradian" )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256
66206
fffcb2d302a5 (math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65592
diff changeset
257 ;; Other physical quantities
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
258 ;; The values are from CODATA, and are approximate.
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
259 ( h "6.62606896*10^(-34) J s" "*Planck's constant" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
260 "6.62606896 10^-34 J s (*)")
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
261 ( hbar "h / (2 pi)" "Planck's constant" ) ;; Exact
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
262 ( mu0 "4 pi 10^(-7) H/m" "Permeability of vacuum") ;; Exact
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
263 ( μ0 "mu0" "Permeability of vacuum") ;; Exact
99729
fa7cdd1157d9 (math-standard-units): Add eps0, permittivity of vacuum.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98540
diff changeset
264 ( eps0 "1 / (mu0 c^2)" "Permittivity of vacuum" )
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
265 ( ε0 "eps0" "Permittivity of vacuum" )
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
266 ( G "6.67428*10^(-11) m^3/(kg s^2)" "Gravitational constant" nil
98540
9496026984da (math-standard-units): More adjustments.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98538
diff changeset
267 "6.67428 10^-11 m^3/(kg s^2) (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
268 ( Nav "6.02214179*10^(23) / mol" "Avogadro's constant" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
269 "6.02214179 10^23 / mol (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
270 ( me "9.10938215*10^(-31) kg" "Electron rest mass" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
271 "9.10938215 10^-31 kg (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
272 ( mp "1.672621637*10^(-27) kg" "Proton rest mass" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
273 "1.672621637 10^-27 kg (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
274 ( mn "1.674927211*10^(-27) kg" "Neutron rest mass" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
275 "1.674927211 10^-27 kg (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
276 ( mmu "1.88353130*10^(-28) kg" "Muon rest mass" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
277 "1.88353130 10^-28 kg (*)")
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
278 ( mμ "mmu" "Muon rest mass" nil
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
279 "1.88353130 10^-28 kg (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
280 ( Ryd "10973731.568527 /m" "Rydberg's constant" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
281 "10973731.568527 /m (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
282 ( k "1.3806504*10^(-23) J/K" "Boltzmann's constant" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
283 "1.3806504 10^-23 J/K (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
284 ( alpha "7.2973525376*10^(-3)" "Fine structure constant" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
285 "7.2973525376 10^-3 (*)")
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
286 ( α "alpha" "Fine structure constant" nil
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
287 "7.2973525376 10^-3 (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
288 ( muB "927.400915*10^(-26) J/T" "Bohr magneton" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
289 "927.400915 10^-26 J/T (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
290 ( muN "5.05078324*10^(-27) J/T" "Nuclear magneton" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
291 "5.05078324 10^-27 J/T (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
292 ( mue "-928.476377*10^(-26) J/T" "Electron magnetic moment" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
293 "-928.476377 10^-26 J/T (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
294 ( mup "1.410606662*10^(-26) J/T" "Proton magnetic moment" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
295 "1.410606662 10^-26 J/T (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
296 ( R0 "8.314472 J/(mol K)" "Molar gas constant" nil
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
297 "8.314472 J/(mol K) (*)")
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
298 ( V0 "22.710981*10^(-3) m^3/mol" "Standard volume of ideal gas" nil
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
299 "22.710981 10^-3 m^3/mol (*)")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (defvar math-additional-units nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 "*Additional units table for user-defined units.
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
304 Must be formatted like `math-standard-units'.
99738
f84e322e603e (math-additional-units): Doc fix (active voice).
Glenn Morris <rgm@gnu.org>
parents: 99732
diff changeset
305 If you change this, be sure to set `math-units-table' to nil to ensure
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 that the combined units table will be rebuilt.")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (defvar math-unit-prefixes
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
309 '( ( ?Y (^ 10 24) "Yotta" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
310 ( ?Z (^ 10 21) "Zetta" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
311 ( ?E (^ 10 18) "Exa" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
312 ( ?P (^ 10 15) "Peta" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
313 ( ?T (^ 10 12) "Tera" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
314 ( ?G (^ 10 9) "Giga" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
315 ( ?M (^ 10 6) "Mega" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
316 ( ?k (^ 10 3) "Kilo" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
317 ( ?K (^ 10 3) "Kilo" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
318 ( ?h (^ 10 2) "Hecto" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
319 ( ?H (^ 10 2) "Hecto" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
320 ( ?D (^ 10 1) "Deka" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
321 ( 0 (^ 10 0) nil )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
322 ( ?d (^ 10 -1) "Deci" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
323 ( ?c (^ 10 -2) "Centi" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
324 ( ?m (^ 10 -3) "Milli" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
325 ( ?u (^ 10 -6) "Micro" )
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
326 ( ?μ (^ 10 -6) "Micro" )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
327 ( ?n (^ 10 -9) "Nano" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
328 ( ?p (^ 10 -12) "Pico" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
329 ( ?f (^ 10 -15) "Femto" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
330 ( ?a (^ 10 -18) "Atto" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
331 ( ?z (^ 10 -21) "zepto" )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
332 ( ?y (^ 10 -24) "yocto" )))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (defvar math-standard-units-systems
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 '( ( base nil )
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
336 ( si ( ( g '(/ (var kg var-kg) 1000) ) ) )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
337 ( mks ( ( g '(/ (var kg var-kg) 1000) ) ) )
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
338 ( cgs ( ( m '(* (var cm var-cm) 100 ) ) ) )))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340 (defvar math-units-table nil
99732
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
341 "Internal units table.
651a986bea61 * calc/calc-units.el (math-units-table): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 99729
diff changeset
342 Derived from `math-standard-units' and `math-additional-units'.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345 (defvar math-units-table-buffer-valid nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
347 ;;; Units commands.
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
348
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
349 (defun calc-base-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
350 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
351 (calc-slow-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
352 (let ((calc-autorange-units nil))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
353 (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
354 (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
355 nil))))))
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-quick-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
358 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
359 (calc-slow-wrapper
101001
14b421290b2f Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
360 (let* ((num (- last-command-event ?0))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
361 (pos (if (= num 0) 10 num))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
362 (units (calc-var-value 'var-Units))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
363 (expr (calc-top-n 1)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
364 (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
365 (error "Bad unit number"))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
366 (unless (math-vectorp units)
57130
d8cdadecaba8 (calc-quick-units): Fix overzealous s/or/unless.
John Paul Wallington <jpw@pobox.com>
parents: 52401
diff changeset
367 (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
368 (unless (< pos (length units))
57130
d8cdadecaba8 (calc-quick-units): Fix overzealous s/or/unless.
John Paul Wallington <jpw@pobox.com>
parents: 52401
diff changeset
369 (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
370 (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
371 (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
372 (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
373 (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
374 (math-simplify-units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
375 (math-mul expr (nth pos units))))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
376
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
377 (defun math-get-standard-units (expr)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
378 "Return the standard units in EXPR."
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
379 (math-simplify-units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
380 (math-extract-units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
381 (math-to-standard-units expr nil))))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
382
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
383 (defun math-get-units (expr)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
384 "Return the units in EXPR."
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
385 (math-simplify-units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
386 (math-extract-units expr)))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
387
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
388 (defun math-make-unit-string (expr)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
389 "Return EXPR in string form.
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
390 If EXPR is nil, return nil."
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
391 (if expr
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
392 (let ((cexpr (math-compose-expr expr 0)))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
393 (replace-regexp-in-string
82390
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
394 " / " "/"
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
395 (if (stringp cexpr)
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
396 cexpr
c315336c2be8 (math-standard-units): Update values. Put in exact values when
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82368
diff changeset
397 (math-composition-to-string cexpr))))))
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
398
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
399 (defvar math-default-units-table
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
400 (make-hash-table :test 'equal)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
401 "A table storing previously converted units.")
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
402
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
403 (defun math-get-default-units (expr)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
404 "Get default units to use when converting the units in EXPR."
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
405 (let* ((units (math-get-units expr))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
406 (standard-units (math-get-standard-units expr))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
407 (default-units (gethash
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
408 standard-units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
409 math-default-units-table)))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
410 (if (equal units (car default-units))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
411 (math-make-unit-string (cadr default-units))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
412 (math-make-unit-string (car default-units)))))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
413
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
414 (defun math-put-default-units (expr)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
415 "Put the units in EXPR in the default units table."
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
416 (let* ((units (math-get-units expr))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
417 (standard-units (math-get-standard-units expr))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
418 (default-units (gethash
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
419 standard-units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
420 math-default-units-table)))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
421 (cond
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
422 ((not default-units)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
423 (puthash standard-units (list units) math-default-units-table))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
424 ((not (equal units (car default-units)))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
425 (puthash standard-units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
426 (list units (car default-units))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
427 math-default-units-table)))))
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
428
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
429
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
430 (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
431 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
432 (calc-slow-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
433 (let ((expr (calc-top-n 1))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
434 (uoldname nil)
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
435 unew
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
436 units
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
437 defunits)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
438 (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
439 (let ((uold (or old-units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
440 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
441 (setq uoldname (read-string "Old units: "))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
442 (if (equal uoldname "")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
443 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
444 (setq uoldname "1")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
445 1)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
446 (if (string-match "\\` */" uoldname)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
447 (setq uoldname (concat "1" uoldname)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
448 (math-read-expr uoldname))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
449 (when (eq (car-safe uold) 'error)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
450 (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
451 (setq expr (math-mul expr uold))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
452 (unless new-units
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
453 (setq defunits (math-get-default-units expr))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
454 (setq new-units
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
455 (read-string (concat
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
456 (if uoldname
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
457 (concat "Old units: "
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
458 uoldname
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
459 ", new units")
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
460 "New units")
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
461 (if defunits
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
462 (concat
84936
9f0f3499c174 (calc-convert-units, calc-convert-temperature): Remove unnecessary
Jay Belanger <jay.p.belanger@gmail.com>
parents: 84891
diff changeset
463 " (default "
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
464 defunits
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
465 "): ")
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
466 ": "))))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
467
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
468 (if (and
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
469 (string= new-units "")
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
470 defunits)
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
471 (setq new-units defunits)))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
472 (when (string-match "\\` */" new-units)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
473 (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
474 (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
475 (when (eq (car-safe units) 'error)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
476 (error "Bad format in units expression: %s" (nth 2 units)))
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
477 (math-put-default-units units)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
478 (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
479 (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
480 (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
481 (if std
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
482 (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
483 (math-to-standard-units expr
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
484 (nth 1 std))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
485 (unless unew
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
486 (error "No units specified"))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
487 (calc-enter-result 1 "cvun"
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
488 (math-convert-units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
489 expr units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
490 (and uoldname (not (equal uoldname "1"))))))))))
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-autorange-units (arg)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
493 (interactive "P")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
494 (calc-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
495 (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
496 (message (if calc-autorange-units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
497 "Adjusting target unit prefix automatically"
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
498 "Using target units exactly"))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
499
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
500 (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
501 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
502 (calc-slow-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
503 (let ((expr (calc-top-n 1))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
504 (uold nil)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
505 (uoldname nil)
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
506 unew
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
507 defunits)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
508 (setq uold (or old-units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
509 (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
510 (if units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
511 (if (consp units)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
512 (list 'var (car units)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
513 (intern (concat "var-"
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
514 (symbol-name
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
515 (car units)))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
516 (error "Not a pure temperature expression"))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
517 (math-read-expr
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
518 (setq uoldname (read-string
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
519 "Old temperature units: ")))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
520 (when (eq (car-safe uold) 'error)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
521 (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
522 (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
523 (setq expr (math-mul expr uold)))
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
524 (setq defunits (math-get-default-units expr))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
525 (setq unew (or new-units
98201
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
526 (read-string
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
527 (concat
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
528 (if uoldname
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
529 (concat "Old temperature units: "
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
530 uoldname
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
531 ", new units")
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
532 "New temperature units")
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
533 (if defunits
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
534 (concat " (default "
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
535 defunits
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
536 "): ")
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
537 ": ")))))
1d82f8f9b231 (calc-convert-temperature): Use default units when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
538 (setq unew (math-read-expr (if (string= unew "") defunits unew)))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
539 (when (eq (car-safe unew) 'error)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
540 (error "Bad format in units expression: %s" (nth 2 unew)))
82368
030fcc9e29ab (math-get-standard-units,math-get-units,math-make-unit-string)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82325
diff changeset
541 (math-put-default-units unew)
87499
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
542 (let ((ntemp (calc-normalize
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
543 (math-simplify-units
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
544 (math-convert-temperature expr uold unew
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
545 uoldname)))))
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
546 (if (Math-zerop ntemp)
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
547 (setq ntemp (list '* ntemp unew)))
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
548 (let ((calc-simplify-mode 'none))
a0abd1e93db8 (calc-convert-temperature): Ensure that units are on the result
Jay Belanger <jay.p.belanger@gmail.com>
parents: 85603
diff changeset
549 (calc-enter-result 1 "cvtm" ntemp))))))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
550
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
551 (defun calc-remove-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
552 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
553 (calc-slow-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
554 (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
555 (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
556
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
557 (defun calc-extract-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
558 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
559 (calc-slow-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
560 (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
561 (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
562
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
563 ;; The variables calc-num-units and calc-den-units are local to
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
564 ;; 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
565 ;; 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
566 (defvar calc-num-units)
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
567 (defvar calc-den-units)
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
568
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
569 (defun calc-explain-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
570 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
571 (calc-wrapper
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
572 (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
573 (calc-den-units nil))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
574 (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
575 (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
576 (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
577 (if calc-num-units
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
578 (if calc-den-units
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
579 (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
580 (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
581 (if calc-den-units
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
582 (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
583 (message "No units in expression"))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
584
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
585 (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
586 (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
587 pos)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
588 (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
589 (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
590 (if (eq (aref name 0) ?\*)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
591 (setq name (substring name 1)))
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
592 (if (string-match "[^a-zA-Zα-ωΑ-Ω0-9']" name)
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
593 (if (string-match "^[a-zA-Zα-ωΑ-Ω0-9' ()]*$" name)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
594 (while (setq pos (string-match "[ ()]" name))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
595 (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
596 (if (eq (aref name pos) 32) "-" "")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
597 (substring name (1+ pos)))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
598 (setq name (concat "(" name ")"))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
599 (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
600 (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
601 (nth 1 expr)) 0)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
602 math-unit-prefixes))
108590
c84578d13e42 calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
603 (if (and (string-match "[^a-zA-Zα-ωΑ-Ω0-9']" name)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
604 (not (memq (car u) '(mHg gf))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
605 (concat "-" name)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
606 (downcase name)))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
607 (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
608 (math-equal-int pow -1)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
609 ((or (math-equal-int pow 2)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
610 (math-equal-int pow -2))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
611 (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
612 (setq name (concat "Square-" name))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
613 (setq name (concat name "-squared"))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
614 ((or (math-equal-int pow 3)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
615 (math-equal-int pow -3))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
616 (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
617 (setq name (concat "Cubic-" name))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
618 (setq name (concat name "-cubed"))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
619 (t
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
620 (setq name (concat name "^"
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
621 (math-format-number (math-abs pow))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
622 (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
623 (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
624 (concat calc-num-units " " name)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
625 name))
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
626 (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
627 (concat calc-den-units " " name)
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
628 name))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
629 (cond ((eq (car-safe expr) '*)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
630 (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
631 (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
632 ((eq (car-safe expr) '/)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
633 (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
634 (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
635 ((memq (car-safe expr) '(neg + -))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
636 (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
637 ((and (eq (car-safe expr) '^)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
638 (math-realp (nth 2 expr)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
639 (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
640 (math-mul pow (nth 2 expr))))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
641
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
642 (defun calc-simplify-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
643 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
644 (calc-slow-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
645 (calc-with-default-simplification
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
646 (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
647
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
648 (defun calc-view-units-table (n)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
649 (interactive "P")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
650 (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
651 (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
652 (if (and win
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
653 math-units-table
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
654 math-units-table-buffer-valid)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
655 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
656 (bury-buffer (window-buffer win))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
657 (let ((curwin (selected-window)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
658 (select-window win)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
659 (switch-to-buffer nil)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
660 (select-window curwin)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
661 (math-build-units-table-buffer nil))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
662
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
663 (defun calc-enter-units-table (n)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
664 (interactive "P")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
665 (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
666 (math-build-units-table-buffer t)
65592
1038e6fc7f28 message format spec fixes, commit # 11
Deepak Goel <deego@gnufans.org>
parents: 64325
diff changeset
667 (message "%s" (substitute-command-keys "Type \\[calc] to return to the Calculator")))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
668
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
669 (defun calc-define-unit (uname desc &optional disp)
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
670 (interactive "SDefine unit name: \nsDescription: \nP")
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
671 (if disp (setq disp (read-string "Display definition: ")))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
672 (calc-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
673 (let ((form (calc-top-n 1))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
674 (unit (assq uname math-additional-units)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
675 (or unit
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
676 (setq math-additional-units
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
677 (cons (setq unit (list uname nil nil nil nil))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
678 math-additional-units)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
679 math-units-table nil))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
680 (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
681 (eq (nth 1 form) uname)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
682 (not (math-equal-int form 1))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
683 (math-format-flat-expr form 0)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
684 (setcar (cdr (cdr unit)) (and (not (equal desc ""))
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
685 desc))
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
686 (if disp
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
687 (setcar (cdr (cdr (cdr (cdr unit)))) disp))))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
688 (calc-invalidate-units-table))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
689
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
690 (defun calc-undefine-unit (uname)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
691 (interactive "SUndefine unit name: ")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
692 (calc-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
693 (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
694 (or unit
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
695 (if (assq uname math-standard-units)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
696 (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
697 (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
698 (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
699 math-units-table nil)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
700 (calc-invalidate-units-table))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
701
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
702 (defun calc-invalidate-units-table ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
703 (setq math-units-table nil)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
704 (let ((buf (get-buffer "*Units Table*")))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
705 (and buf
105792
2c12fbae77c2 * calc/calc.el (calc, calc-refresh, calc-trail-buffer, calc-record)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101001
diff changeset
706 (with-current-buffer buf
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
707 (save-excursion
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
708 (goto-char (point-min))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
709 (if (looking-at "Calculator Units Table")
62565
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
710 (let ((inhibit-read-only t))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
711 (insert "(Obsolete) "))))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
712
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
713 (defun calc-get-unit-definition (uname)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
714 (interactive "SGet definition for unit: ")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
715 (calc-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
716 (math-build-units-table)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
717 (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
718 (or unit
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
719 (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
720 (let ((msg (nth 2 unit)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
721 (if (stringp msg)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
722 (if (string-match "^\\*" msg)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
723 (setq msg (substring msg 1)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
724 (setq msg (symbol-name uname)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
725 (if (nth 1 unit)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
726 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
727 (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
728 (message "Derived unit: %s" msg))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
729 (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
730 (intern
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
731 (concat "var-"
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
732 (symbol-name uname)))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
733 (message "Base unit: %s" msg))))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
734
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
735 (defun calc-permanent-units ()
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
736 (interactive)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
737 (calc-wrapper
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
738 (let (pos)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
739 (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
740 calc-settings-file)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
741 (goto-char (point-min))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
742 (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
743 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
744 (beginning-of-line)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
745 (setq pos (point))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
746 (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
747 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
748 (beginning-of-line)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
749 (forward-line 1)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
750 (delete-region pos (point)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
751 (goto-char (point-max))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
752 (insert "\n\n")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
753 (forward-char -1))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
754 (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
755 (if math-additional-units
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
756 (progn
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
757 (insert "(setq math-additional-units '(\n")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
758 (let ((list math-additional-units))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
759 (while list
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
760 (insert " (" (symbol-name (car (car list))) " "
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
761 (if (nth 1 (car list))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
762 (if (stringp (nth 1 (car list)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
763 (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
764 (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
765 (nth 1 (car list)) 0)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
766 "nil")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
767 " "
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
768 (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
769 ")\n")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
770 (setq list (cdr list))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
771 (insert "))\n"))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
772 (insert ";;; (no custom units defined)\n"))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
773 (insert ";;; End of custom units\n")
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
774 (save-buffer))))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
775
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
776
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
777 ;; 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
778 ;; 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
779 ;; 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
780 ;; 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
781 ;; 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
782 (defvar math-cu-unit-list)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
783
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
784 (defun math-build-units-table ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
785 (or math-units-table
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
786 (let* ((combined-units (append math-additional-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
787 math-standard-units))
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
788 (math-cu-unit-list (mapcar 'car combined-units))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
789 tab)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
790 (message "Building units table...")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
791 (setq math-units-table-buffer-valid nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
792 (setq tab (mapcar (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
793 (lambda (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
794 (list (car x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
795 (and (nth 1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
796 (if (stringp (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
797 (let ((exp (math-read-plain-expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
798 (nth 1 x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
799 (if (eq (car-safe exp) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
800 (error "Format error in definition of %s in units table: %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
801 (car x) (nth 2 exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802 exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
803 (nth 1 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
804 (nth 2 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
805 (nth 3 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
806 (and (not (nth 1 x))
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
807 (list (cons (car x) 1)))
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
808 (nth 4 x))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
809 combined-units))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
810 (let ((math-units-table tab))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
811 (mapc 'math-find-base-units tab))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
812 (message "Building units table...done")
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
813 (setq math-units-table tab))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
814
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
815 ;; 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
816 ;; 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
817 ;; 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
818 (defvar math-fbu-base)
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
819 (defvar math-fbu-entry)
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
820
58511
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
821 (defun math-find-base-units (math-fbu-entry)
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
822 (if (eq (nth 4 math-fbu-entry) 'boom)
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
823 (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
824 (or (nth 4 math-fbu-entry)
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
825 (let (math-fbu-base)
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
826 (setcar (nthcdr 4 math-fbu-entry) 'boom)
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
827 (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
828 '(or math-fbu-base
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
829 (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
830 (while (eq (cdr (car math-fbu-base)) 0)
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
831 (setq math-fbu-base (cdr math-fbu-base)))
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
832 (let ((b math-fbu-base))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
833 (while (cdr b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
834 (if (eq (cdr (car (cdr b))) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
835 (setcdr b (cdr (cdr b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
836 (setq b (cdr b)))))
58511
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
837 (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
838 (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
839 math-fbu-base)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
840
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
841 (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
842 (memq (car b) (cdr (memq (car a) math-cu-unit-list))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
843
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
844 (defun math-find-base-units-rec (expr pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
845 (let ((u (math-check-unit-name expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
846 (cond (u
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
847 (let ((ulist (math-find-base-units u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
848 (while ulist
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
849 (let ((p (* (cdr (car ulist)) pow))
58511
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
850 (old (assq (car (car ulist)) math-fbu-base)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
851 (if old
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
852 (setcdr old (+ (cdr old) p))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
853 (setq math-fbu-base
58511
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
854 (cons (cons (car (car ulist)) p) math-fbu-base))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
855 (setq ulist (cdr ulist)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
856 ((math-scalarp expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
857 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
858 (integerp (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
859 (math-find-base-units-rec (nth 1 expr) (* pow (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
860 ((eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
861 (math-find-base-units-rec (nth 1 expr) pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
862 (math-find-base-units-rec (nth 2 expr) pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
863 ((eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
864 (math-find-base-units-rec (nth 1 expr) pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
865 (math-find-base-units-rec (nth 2 expr) (- pow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
866 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
867 (math-find-base-units-rec (nth 1 expr) pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
868 ((eq (car expr) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
869 (math-find-base-units-rec (nth 1 expr) pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
870 ((eq (car expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
871 (or (eq (nth 1 expr) 'pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
872 (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
873 (nth 1 expr) (car math-fbu-entry))))
0a3797785946 Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58508
diff changeset
874 (t (error "Malformed defining expression for unit %s" (car math-fbu-entry))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
875
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
876
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
877 (defun math-units-in-expr-p (expr sub-exprs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
878 (and (consp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
879 (if (eq (car expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
880 (math-check-unit-name expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
881 (and (or sub-exprs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
882 (memq (car expr) '(* / ^)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
883 (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
884 (math-units-in-expr-p (nth 2 expr) sub-exprs))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
885
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
886 (defun math-only-units-in-expr-p (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
887 (and (consp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
888 (if (eq (car expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
889 (math-check-unit-name expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
890 (if (memq (car expr) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
891 (and (math-only-units-in-expr-p (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
892 (math-only-units-in-expr-p (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
893 (and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
894 (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
895 (math-realp (nth 2 expr))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
896
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
897 (defun math-single-units-in-expr-p (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
898 (cond ((math-scalarp expr) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
899 ((eq (car expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
900 (math-check-unit-name expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
901 ((eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
902 (let ((u1 (math-single-units-in-expr-p (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
903 (u2 (math-single-units-in-expr-p (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
904 (or (and u1 u2 'wrong)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
905 u1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
906 u2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
907 ((eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
908 (if (math-units-in-expr-p (nth 2 expr) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
909 'wrong
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
910 (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
911 (t 'wrong)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
912
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
913 (defun math-check-unit-name (v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
914 (and (eq (car-safe v) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
915 (or (assq (nth 1 v) (or math-units-table (math-build-units-table)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
916 (let ((name (symbol-name (nth 1 v))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
917 (and (> (length name) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
918 (assq (aref name 0) math-unit-prefixes)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
919 (or (assq (intern (substring name 1)) math-units-table)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
920 (and (eq (aref name 0) ?M)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
921 (> (length name) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
922 (eq (aref name 1) ?e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
923 (eq (aref name 2) ?g)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
924 (assq (intern (substring name 3))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
925 math-units-table))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
926
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
927 ;; 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
928 ;; 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
929 ;; 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 (defvar math-which-standard)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
931
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
932 (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
933 (math-to-standard-rec expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
934
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
935 (defun math-to-standard-rec (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
936 (if (eq (car-safe expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
937 (let ((u (math-check-unit-name expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
938 (base (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
939 (if u
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
940 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
941 (if (nth 1 u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
942 (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
943 (let ((st (assq (car u) math-which-standard)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
944 (if st
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
945 (setq expr (nth 1 st))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
946 (setq expr (list 'var (car u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
947 (intern (concat "var-"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
948 (symbol-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
949 (car u)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
950 (or (null u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
951 (eq base (car u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
952 (setq expr (list '*
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
953 (nth 1 (assq (aref (symbol-name base) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
954 math-unit-prefixes))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
955 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
956 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
957 (if (eq base 'pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
958 (math-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
959 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
960 (if (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
961 expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
962 (cons (car expr)
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
963 (mapcar 'math-to-standard-rec (cdr expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
964
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
965 (defun math-apply-units (expr units ulist &optional pure)
64163
f3c30d255a4d (math-apply-units): Change the places in which units are simplified.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62565
diff changeset
966 (setq expr (math-simplify-units expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
967 (if ulist
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
968 (let ((new 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
969 value)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
970 (or (math-numberp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
971 (error "Incompatible units"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
972 (while (cdr ulist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
973 (setq value (math-div expr (nth 1 (car ulist)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
974 value (math-floor (let ((calc-internal-prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
975 (1- calc-internal-prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
976 (math-normalize value)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
977 new (math-add new (math-mul value (car (car ulist))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
978 expr (math-sub expr (math-mul value (nth 1 (car ulist))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
979 ulist (cdr ulist)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
980 (math-add new (math-mul (math-div expr (nth 1 (car ulist)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
981 (car (car ulist)))))
64163
f3c30d255a4d (math-apply-units): Change the places in which units are simplified.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62565
diff changeset
982 (if pure
f3c30d255a4d (math-apply-units): Change the places in which units are simplified.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62565
diff changeset
983 expr
f3c30d255a4d (math-apply-units): Change the places in which units are simplified.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62565
diff changeset
984 (math-simplify-units (list '* expr units)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
985
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
986 (defvar math-decompose-units-cache nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
987 (defun math-decompose-units (units)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
988 (let ((u (math-check-unit-name units)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
989 (and u (eq (car-safe (nth 1 u)) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
990 (setq units (nth 1 u))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
991 (setq units (calcFunc-expand units))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
992 (and (eq (car-safe units) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
993 (let ((entry (list units calc-internal-prec calc-prefer-frac)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
994 (or (equal entry (car math-decompose-units-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
995 (let ((ulist nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
996 (utemp units)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
997 qty unit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
998 (while (eq (car-safe utemp) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
999 (setq ulist (cons (math-decompose-unit-part (nth 2 utemp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1000 ulist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1001 utemp (nth 1 utemp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1002 (setq ulist (cons (math-decompose-unit-part utemp) ulist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1003 utemp ulist)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1004 (while (setq utemp (cdr utemp))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1005 (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
1006 (error "Inconsistent units in sum")))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1007 (setq math-decompose-units-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1008 (cons entry
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1009 (sort ulist
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1010 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1011 (lambda (x y)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1012 (not (Math-lessp (nth 1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1013 (nth 1 y))))))))))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1014 (cdr math-decompose-units-cache))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1015
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1016 (defun math-decompose-unit-part (unit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1017 (cons unit
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1018 (math-is-multiple (math-simplify-units (math-to-standard-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1019 unit nil))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1020 t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1021
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1022 ;; 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
1023 ;; 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
1024 ;; math-find-compatible-unit.
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1025 (defvar math-fcu-u)
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1026
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1027 (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
1028 (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
1029 (if math-fcu-u
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1030 (math-find-compatible-unit-rec expr 1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1031
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1032 (defun math-find-compatible-unit-rec (expr pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1033 (cond ((eq (car-safe expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1034 (or (math-find-compatible-unit-rec (nth 1 expr) pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1035 (math-find-compatible-unit-rec (nth 2 expr) pow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1036 ((eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1037 (or (math-find-compatible-unit-rec (nth 1 expr) pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1038 (math-find-compatible-unit-rec (nth 2 expr) (- pow))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1039 ((and (eq (car-safe expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1040 (integerp (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1041 (math-find-compatible-unit-rec (nth 1 expr) (* pow (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1042 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1043 (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
1044 (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
1045 (cons expr pow))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1046
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1047 ;; The variables math-cu-new-units and math-cu-pure are local to
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1048 ;; math-convert-units, but are used by math-convert-units-rec,
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1049 ;; 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
1050 (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
1051 (defvar math-cu-pure)
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1052
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1053 (defun math-convert-units (expr math-cu-new-units &optional math-cu-pure)
66753
2f681ffeffdf (math-convert-units): Replace any composite unit by its definition.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66206
diff changeset
1054 (if (eq (car-safe math-cu-new-units) 'var)
2f681ffeffdf (math-convert-units): Replace any composite unit by its definition.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66206
diff changeset
1055 (let ((unew (assq (nth 1 math-cu-new-units)
2f681ffeffdf (math-convert-units): Replace any composite unit by its definition.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66206
diff changeset
1056 (math-build-units-table))))
2f681ffeffdf (math-convert-units): Replace any composite unit by its definition.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66206
diff changeset
1057 (if (eq (car-safe (nth 1 unew)) '+)
2f681ffeffdf (math-convert-units): Replace any composite unit by its definition.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66206
diff changeset
1058 (setq math-cu-new-units (nth 1 unew)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1059 (math-with-extra-prec 2
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1060 (let ((compat (and (not math-cu-pure)
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1061 (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
1062 (math-cu-unit-list nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1063 (math-combining-units nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1064 (if compat
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1065 (math-simplify-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1066 (math-mul (math-mul (math-simplify-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1067 (math-div expr (math-pow (car compat)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1068 (cdr compat))))
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1069 (math-pow math-cu-new-units (cdr compat)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1070 (math-simplify-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1071 (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
1072 (math-pow (math-div (car compat) math-cu-new-units)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1073 (cdr compat))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1074 nil))))
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1075 (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
1076 (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
1077 (when (eq (car-safe expr) '+)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1078 (setq expr (math-simplify-units expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1079 (if (math-units-in-expr-p expr t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1080 (math-convert-units-rec expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1081 (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
1082 (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
1083 math-cu-new-units math-cu-unit-list math-cu-pure))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1084
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1085 (defun math-convert-units-rec (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1086 (if (math-units-in-expr-p expr nil)
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1087 (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
1088 (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
1089 math-cu-new-units math-cu-unit-list math-cu-pure)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1090 (if (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1091 expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1092 (cons (car expr)
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1093 (mapcar 'math-convert-units-rec (cdr expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1094
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1095 (defun math-convert-temperature (expr old new &optional pure)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1096 (let* ((units (math-single-units-in-expr-p expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1097 (uold (if old
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1098 (if (or (null units)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1099 (equal (nth 1 old) (car units)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1100 (math-check-unit-name old)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1101 (error "Inconsistent temperature units"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1102 units))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1103 (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
1104 (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
1105 (error "Not a valid temperature unit"))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1106 (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
1107 (error "Not a pure temperature expression"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1108 (let ((v (car uold)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1109 (setq expr (list '/ expr (list 'var v
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1110 (intern (concat "var-"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1111 (symbol-name v)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1112 (or (eq (nth 3 uold) (nth 3 unew))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1113 (cond ((eq (nth 3 uold) 'K)
82325
c9f47b4c81d5 (calc-convert-temperature): Use `/' to create fractions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 78215
diff changeset
1114 (setq expr (list '- expr '(/ 27315 100)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1115 (if (eq (nth 3 unew) 'F)
82325
c9f47b4c81d5 (calc-convert-temperature): Use `/' to create fractions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 78215
diff changeset
1116 (setq expr (list '+ (list '* expr '(/ 9 5)) 32))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1117 ((eq (nth 3 uold) 'C)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1118 (if (eq (nth 3 unew) 'F)
82325
c9f47b4c81d5 (calc-convert-temperature): Use `/' to create fractions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 78215
diff changeset
1119 (setq expr (list '+ (list '* expr '(/ 9 5)) 32))
c9f47b4c81d5 (calc-convert-temperature): Use `/' to create fractions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 78215
diff changeset
1120 (setq expr (list '+ expr '(/ 27315 100)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1121 (t
82325
c9f47b4c81d5 (calc-convert-temperature): Use `/' to create fractions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 78215
diff changeset
1122 (setq expr (list '* (list '- expr 32) '(/ 5 9)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1123 (if (eq (nth 3 unew) 'K)
82325
c9f47b4c81d5 (calc-convert-temperature): Use `/' to create fractions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 78215
diff changeset
1124 (setq expr (list '+ expr '(/ 27315 100)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1125 (if pure
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1126 expr
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1127 (list '* expr new))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1128
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1129
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1130
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1131 (defun math-simplify-units (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1132 (let ((math-simplifying-units t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1133 (calc-matrix-mode 'scalar))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1134 (math-simplify a)))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1135 (defalias 'calcFunc-usimplify 'math-simplify-units)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1136
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1137 ;; 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
1138 ;; 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
1139 (defvar math-simplify-expr)
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1140
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1141 (math-defsimplify (+ -)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1142 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1143 (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
1144 (let* ((units (math-extract-units (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1145 (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
1146 (list '/ (nth 2 math-simplify-expr) units) nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1147 (if (math-units-in-expr-p ratio nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1148 (progn
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1149 (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
1150 math-simplify-expr)
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1151 (list '* (math-add (math-remove-units (nth 1 math-simplify-expr))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1152 (if (eq (car math-simplify-expr) '-)
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1153 (math-neg ratio) ratio))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1154 units)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1155
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1156 (math-defsimplify *
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1157 (math-simplify-units-prod))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1158
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1159 (defun math-simplify-units-prod ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1160 (and math-simplifying-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1161 calc-autorange-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1162 (Math-realp (nth 1 math-simplify-expr))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1163 (let* ((num (math-float (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1164 (xpon (calcFunc-xpon num))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1165 (unitp (cdr (cdr math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1166 (unit (car unitp))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1167 (pow (if (eq (car math-simplify-expr) '*) 1 -1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1168 u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1169 (and (eq (car-safe unit) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1170 (setq unitp (cdr unit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1171 unit (car unitp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1172 (and (eq (car-safe unit) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1173 (integerp (nth 2 unit))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1174 (setq pow (* pow (nth 2 unit))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1175 unitp (cdr unit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1176 unit (car unitp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1177 (and (setq u (math-check-unit-name unit))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1178 (integerp xpon)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1179 (or (< xpon 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1180 (>= xpon (if (eq (car u) 'm) 1 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1181 (let* ((uxpon 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1182 (pref (if (< pow 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1183 (reverse math-unit-prefixes)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1184 math-unit-prefixes))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1185 (p pref)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1186 pxpon pname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1187 (or (eq (car u) (nth 1 unit))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1188 (setq uxpon (* pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1189 (nth 2 (nth 1 (assq
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1190 (aref (symbol-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1191 (nth 1 unit)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1192 math-unit-prefixes))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1193 (setq xpon (+ xpon uxpon))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1194 (while (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1195 (or (memq (car (car p)) '(?d ?D ?h ?H))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1196 (and (eq (car (car p)) ?c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1197 (not (eq (car u) 'm)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1198 (< xpon (setq pxpon (* (nth 2 (nth 1 (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1199 pow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1200 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1201 (setq pname (math-build-var-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1202 (if (eq (car (car p)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1203 (car u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1204 (concat (char-to-string
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1205 (car (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1206 (symbol-name
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1207 (car u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1208 (and (/= (car (car p)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1209 (assq (nth 1 pname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1210 math-units-table)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1211 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1212 (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1213 (/= pxpon uxpon)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1214 (or (not (eq p pref))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1215 (< xpon (+ pxpon (* (math-abs pow) 3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1216 (progn
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1217 (setcar (cdr math-simplify-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1218 (let ((calc-prefer-frac nil))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1219 (calcFunc-scf (nth 1 math-simplify-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1220 (- uxpon pxpon))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1221 (setcar unitp pname)
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1222 math-simplify-expr)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1223
58508
589dc235628a (calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58303
diff changeset
1224 (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
1225
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1226 (math-defsimplify /
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1227 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1228 (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
1229 (math-try-cancel-units 0)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1230 n nn)
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1231 (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
1232 (cdr (nth 2 math-simplify-expr))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1233 (nthcdr 2 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1234 (if (math-realp (car n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1235 (progn
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1236 (setcar (cdr math-simplify-expr) (math-mul (nth 1 math-simplify-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1237 (let ((calc-prefer-frac nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1238 (math-div 1 (car n)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1239 (setcar n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1240 (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
1241 (math-simplify-units-divisor (cdr n) (cdr (cdr math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1242 (setq np (cdr (cdr n))))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1243 (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
1244 (if (eq math-try-cancel-units 0)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1245 (let* ((math-simplifying-units nil)
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1246 (base (math-simplify
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1247 (math-to-standard-units math-simplify-expr nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1248 (if (Math-numberp base)
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1249 (setq math-simplify-expr base))))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1250 (if (eq (car-safe math-simplify-expr) '/)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1251 (math-simplify-units-prod))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1252 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1253
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1254 (defun math-simplify-units-divisor (np dp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1255 (let ((n (car np))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1256 d dd temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1257 (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
1258 (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
1259 (setcar np (setq n temp))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1260 (setcar (cdr d) 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1261 (setq dp (cdr (cdr d))))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1262 (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
1263 (setcar np (setq n temp))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1264 (setcar dp 1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1265
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1266 ;; Simplify, e.g., "in / cm" to "2.54" in a units expression.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1267 (defun math-simplify-units-quotient (n d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1268 (let ((pow1 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1269 (pow2 1))
41269
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1270 (when (and (eq (car-safe n) '^)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1271 (integerp (nth 2 n)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1272 (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
1273 (when (and (eq (car-safe d) '^)
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1274 (integerp (nth 2 d)))
8b4a880d7759 (calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents: 41046
diff changeset
1275 (setq pow2 (nth 2 d) d (nth 1 d)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1276 (let ((un (math-check-unit-name n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1277 (ud (math-check-unit-name d)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1278 (and un ud
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1279 (if (and (equal (nth 4 un) (nth 4 ud))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1280 (eq pow1 pow2))
85603
819d86e241bc (math-simplify-units-quotient): Replace missing exponent.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 84936
diff changeset
1281 (if (eq pow1 1)
819d86e241bc (math-simplify-units-quotient): Replace missing exponent.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 84936
diff changeset
1282 (math-to-standard-units (list '/ n d) nil)
819d86e241bc (math-simplify-units-quotient): Replace missing exponent.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 84936
diff changeset
1283 (list '^ (math-to-standard-units (list '/ n d) nil) pow1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1284 (let (ud1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1285 (setq un (nth 4 un)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1286 ud (nth 4 ud))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1287 (while un
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1288 (setq ud1 ud)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1289 (while ud1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1290 (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
1291 (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
1292 (+ math-try-cancel-units
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1293 (- (* (cdr (car un)) pow1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1294 (* (cdr (car ud)) pow2)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1295 (setq ud1 (cdr ud1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1296 (setq un (cdr un)))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1297 nil))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1298
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1299 (math-defsimplify ^
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1300 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1301 (math-realp (nth 2 math-simplify-expr))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1302 (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
1303 (list (car (nth 1 math-simplify-expr))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1304 (list '^ (nth 1 (nth 1 math-simplify-expr))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1305 (nth 2 math-simplify-expr))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1306 (list '^ (nth 2 (nth 1 math-simplify-expr))
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1307 (nth 2 math-simplify-expr)))
84891
1059e5620f1c (math-build-units-table): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 82436
diff changeset
1308 (math-simplify-units-pow (nth 1 math-simplify-expr)
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1309 (nth 2 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1310
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1311 (math-defsimplify calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1312 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1313 (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
1314 (list (car (nth 1 math-simplify-expr))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1315 (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
1316 (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
1317 (math-simplify-units-pow (nth 1 math-simplify-expr) '(frac 1 2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1318
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1319 (math-defsimplify (calcFunc-floor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1320 calcFunc-ceil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1321 calcFunc-round
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1322 calcFunc-rounde
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1323 calcFunc-roundu
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1324 calcFunc-trunc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1325 calcFunc-float
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1326 calcFunc-frac
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1327 calcFunc-abs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1328 calcFunc-clean)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1329 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1330 (= (length math-simplify-expr) 2)
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1331 (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
1332 (nth 1 math-simplify-expr)
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1333 (if (and (memq (car-safe (nth 1 math-simplify-expr)) '(* /))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1334 (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
1335 (nth 1 (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1336 (math-only-units-in-expr-p
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1337 (nth 2 (nth 1 math-simplify-expr)))))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1338 (list (car (nth 1 math-simplify-expr))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1339 (cons (car math-simplify-expr)
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1340 (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
1341 (cdr (cdr math-simplify-expr))))
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1342 (cons (car math-simplify-expr)
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1343 (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
1344 (cdr (cdr math-simplify-expr)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1345
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1346 (defun math-simplify-units-pow (a pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1347 (if (and (eq (car-safe a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1348 (math-check-unit-name (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1349 (math-realp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1350 (list '^ (nth 1 a) (math-mul pow (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1351 (let* ((u (math-check-unit-name a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1352 (pf (math-to-simple-fraction pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1353 (d (and (eq (car-safe pf) 'frac) (nth 2 pf))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1354 (and u d
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1355 (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
1356 (list '^ (math-to-standard-units a nil) pow)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1357
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1358
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1359 (defun math-units-are-multiple (u n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1360 (setq u (nth 4 u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1361 (while (and u (= (% (cdr (car u)) n) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1362 (setq u (cdr u)))
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1363 (null u))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1364
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1365 (math-defsimplify calcFunc-sin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1366 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1367 (math-units-in-expr-p (nth 1 math-simplify-expr) nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1368 (let ((rad (math-simplify-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1369 (math-evaluate-expr
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1370 (math-to-standard-units (nth 1 math-simplify-expr) nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1371 (calc-angle-mode 'rad))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1372 (and (eq (car-safe rad) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1373 (math-realp (nth 1 rad))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1374 (eq (car-safe (nth 2 rad)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1375 (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
1376 (list 'calcFunc-sin (nth 1 rad))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1377
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1378 (math-defsimplify calcFunc-cos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1379 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1380 (math-units-in-expr-p (nth 1 math-simplify-expr) nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1381 (let ((rad (math-simplify-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1382 (math-evaluate-expr
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1383 (math-to-standard-units (nth 1 math-simplify-expr) nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1384 (calc-angle-mode 'rad))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1385 (and (eq (car-safe rad) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1386 (math-realp (nth 1 rad))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1387 (eq (car-safe (nth 2 rad)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1388 (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
1389 (list 'calcFunc-cos (nth 1 rad))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1390
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1391 (math-defsimplify calcFunc-tan
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1392 (and math-simplifying-units
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1393 (math-units-in-expr-p (nth 1 math-simplify-expr) nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1394 (let ((rad (math-simplify-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1395 (math-evaluate-expr
58303
6ae80af2f94b (math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 57130
diff changeset
1396 (math-to-standard-units (nth 1 math-simplify-expr) nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1397 (calc-angle-mode 'rad))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1398 (and (eq (car-safe rad) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1399 (math-realp (nth 1 rad))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1400 (eq (car-safe (nth 2 rad)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1401 (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
1402 (list 'calcFunc-tan (nth 1 rad))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1403
60082
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1404 (math-defsimplify calcFunc-sec
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1405 (and math-simplifying-units
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1406 (math-units-in-expr-p (nth 1 math-simplify-expr) nil)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1407 (let ((rad (math-simplify-units
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1408 (math-evaluate-expr
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1409 (math-to-standard-units (nth 1 math-simplify-expr) nil))))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1410 (calc-angle-mode 'rad))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1411 (and (eq (car-safe rad) '*)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1412 (math-realp (nth 1 rad))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1413 (eq (car-safe (nth 2 rad)) 'var)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1414 (eq (nth 1 (nth 2 rad)) 'rad)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1415 (list 'calcFunc-sec (nth 1 rad))))))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1416
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1417 (math-defsimplify calcFunc-csc
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1418 (and math-simplifying-units
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1419 (math-units-in-expr-p (nth 1 math-simplify-expr) nil)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1420 (let ((rad (math-simplify-units
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1421 (math-evaluate-expr
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1422 (math-to-standard-units (nth 1 math-simplify-expr) nil))))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1423 (calc-angle-mode 'rad))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1424 (and (eq (car-safe rad) '*)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1425 (math-realp (nth 1 rad))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1426 (eq (car-safe (nth 2 rad)) 'var)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1427 (eq (nth 1 (nth 2 rad)) 'rad)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1428 (list 'calcFunc-csc (nth 1 rad))))))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1429
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1430 (math-defsimplify calcFunc-cot
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1431 (and math-simplifying-units
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1432 (math-units-in-expr-p (nth 1 math-simplify-expr) nil)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1433 (let ((rad (math-simplify-units
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1434 (math-evaluate-expr
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1435 (math-to-standard-units (nth 1 math-simplify-expr) nil))))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1436 (calc-angle-mode 'rad))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1437 (and (eq (car-safe rad) '*)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1438 (math-realp (nth 1 rad))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1439 (eq (car-safe (nth 2 rad)) 'var)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1440 (eq (nth 1 (nth 2 rad)) 'rad)
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1441 (list 'calcFunc-cot (nth 1 rad))))))
1697c06499c8 Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 59394
diff changeset
1442
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1443
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1444 (defun math-remove-units (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1445 (if (math-check-unit-name expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1446 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1447 (if (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1448 expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1449 (cons (car expr)
41046
14b73d89514a (calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1450 (mapcar 'math-remove-units (cdr expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1451
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1452 (defun math-extract-units (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1453 (if (memq (car-safe expr) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1454 (cons (car expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1455 (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
1456 (if (math-check-unit-name expr) expr 1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1457
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1458 (defun math-build-units-table-buffer (enter-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1459 (if (not (and math-units-table math-units-table-buffer-valid
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1460 (get-buffer "*Units Table*")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1461 (let ((buf (get-buffer-create "*Units Table*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1462 (uptr (math-build-units-table))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1463 (calc-language (if (eq calc-language 'big) nil calc-language))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1464 (calc-float-format '(float 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1465 (calc-group-digits nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1466 (calc-number-radix 10)
106145
ba9f3a2508e3 (math-build-units-table-buffer): Let `calc-twos-complement-mode' be nil.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 105792
diff changeset
1467 (calc-twos-complement-mode nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1468 (calc-point-char ".")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1469 (std nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1470 u name shadowed)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1471 (save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1472 (message "Formatting units table...")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1473 (set-buffer buf)
62565
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1474 (let ((inhibit-read-only t))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1475 (erase-buffer)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1476 (insert "Calculator Units Table:\n\n")
98538
e216a9ffc756 (math-standard-units): Update the values of the units.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98400
diff changeset
1477 (insert "(All definitions are exact unless marked with an asterisk (*).)\n\n")
62565
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1478 (insert "Unit Type Definition Description\n\n")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1479 (while uptr
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1480 (setq u (car uptr)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1481 name (nth 2 u))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1482 (when (eq (car u) 'm)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1483 (setq std t))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1484 (setq shadowed (and std (assq (car u) math-additional-units)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1485 (when (and name
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1486 (> (length name) 1)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1487 (eq (aref name 0) ?\*))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1488 (unless (eq uptr math-units-table)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1489 (insert "\n"))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1490 (setq name (substring name 1)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1491 (insert " ")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1492 (and shadowed (insert "("))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1493 (insert (symbol-name (car u)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1494 (and shadowed (insert ")"))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1495 (if (nth 3 u)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1496 (progn
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1497 (indent-to 10)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1498 (insert (symbol-name (nth 3 u))))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1499 (or std
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1500 (progn
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1501 (indent-to 10)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1502 (insert "U"))))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1503 (indent-to 14)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1504 (and shadowed (insert "("))
98400
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
1505 (if (nth 5 u)
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
1506 (insert (nth 5 u))
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
1507 (if (nth 1 u)
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
1508 (insert (math-format-value (nth 1 u) 80))
f9165517710c (math-standard-units): Add entries used to display the the values in the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 98201
diff changeset
1509 (insert (symbol-name (car u)))))
62565
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1510 (and shadowed (insert ")"))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1511 (indent-to 41)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1512 (insert " ")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1513 (when name
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1514 (insert name))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1515 (if shadowed
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1516 (insert " (redefined above)")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1517 (unless (nth 1 u)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1518 (insert " (base unit)")))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1519 (insert "\n")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1520 (setq uptr (cdr uptr)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1521 (insert "\n\nUnit Prefix Table:\n\n")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1522 (setq uptr math-unit-prefixes)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1523 (while uptr
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1524 (setq u (car uptr))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1525 (insert " " (char-to-string (car u)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1526 (if (equal (nth 1 u) (nth 1 (nth 1 uptr)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1527 (insert " " (char-to-string (car (car (setq uptr (cdr uptr)))))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1528 " ")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1529 (insert " "))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1530 (insert "10^" (int-to-string (nth 2 (nth 1 u))))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1531 (indent-to 15)
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1532 (insert " " (nth 2 u) "\n")
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1533 (while (eq (car (car (setq uptr (cdr uptr)))) 0)))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1534 (insert "\n"))
2b285bf6f228 (calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 61412
diff changeset
1535 (view-mode)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1536 (message "Formatting units table...done"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1537 (setq math-units-table-buffer-valid t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1538 (let ((oldbuf (current-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1539 (set-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1540 (goto-char (point-min))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1541 (set-buffer oldbuf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1542 (if enter-buffer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1543 (pop-to-buffer buf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1544 (display-buffer buf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1545 (if enter-buffer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1546 (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
1547 (display-buffer (get-buffer "*Units Table*")))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1548
58677
5ef7cf7f3b8f Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58511
diff changeset
1549 (provide 'calc-units)
5ef7cf7f3b8f Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58511
diff changeset
1550
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
1551 ;; 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
1552 ;;; calc-units.el ends here