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