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