Mercurial > emacs
annotate lisp/calc/calc-units.el @ 78876:6824f67c5a37
(file-name-sans-versions): Also allow `A-Z'.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sat, 22 Sep 2007 17:52:17 +0000 |
parents | 095d08e7d6bb |
children | 9754bb0422ed c9f47b4c81d5 f55f9811f5d7 |
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" ) |
fffcb2d302a5
(math-standard-units): Add units, adjust symbols and update values.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65592
diff
changeset
|
52 ( in "2.54 cm" "Inch" ) |
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 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
324 (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
|
325 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
326 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
327 (let ((expr (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
328 (uoldname nil) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
329 unew |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
330 units) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
331 (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
|
332 (let ((uold (or old-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
333 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
334 (setq uoldname (read-string "Old units: ")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
335 (if (equal uoldname "") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
336 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
337 (setq uoldname "1") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
338 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
339 (if (string-match "\\` */" uoldname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
340 (setq uoldname (concat "1" uoldname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
341 (math-read-expr uoldname)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
342 (when (eq (car-safe uold) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
343 (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
|
344 (setq expr (math-mul expr uold)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
345 (unless new-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
346 (setq new-units (read-string (if uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
347 (concat "Old units: " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
348 uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
349 ", new units: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
350 "New units: ")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
351 (when (string-match "\\` */" new-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
352 (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
|
353 (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
|
354 (when (eq (car-safe units) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
355 (error "Bad format in units expression: %s" (nth 2 units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
356 (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
|
357 (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
|
358 (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
|
359 (if std |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
360 (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
|
361 (math-to-standard-units expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
362 (nth 1 std)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
363 (unless unew |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
364 (error "No units specified")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
365 (calc-enter-result 1 "cvun" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
366 (math-convert-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
367 expr units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
368 (and uoldname (not (equal uoldname "1")))))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
369 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
370 (defun calc-autorange-units (arg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
371 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
372 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
373 (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
|
374 (message (if calc-autorange-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
375 "Adjusting target unit prefix automatically" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
376 "Using target units exactly")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
377 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
378 (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
|
379 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
380 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
381 (let ((expr (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
382 (uold nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
383 (uoldname nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
384 unew) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
385 (setq uold (or old-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
386 (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
|
387 (if units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
388 (if (consp units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
389 (list 'var (car units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
390 (intern (concat "var-" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
391 (symbol-name |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
392 (car units))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
393 (error "Not a pure temperature expression")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
394 (math-read-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
395 (setq uoldname (read-string |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
396 "Old temperature units: "))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
397 (when (eq (car-safe uold) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
398 (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
|
399 (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
|
400 (setq expr (math-mul expr uold))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
401 (setq unew (or new-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
402 (math-read-expr |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
403 (read-string (if uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
404 (concat "Old temperature units: " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
405 uoldname |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
406 ", new units: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
407 "New temperature units: "))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
408 (when (eq (car-safe unew) 'error) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
409 (error "Bad format in units expression: %s" (nth 2 unew))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
410 (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
|
411 (math-convert-temperature expr uold unew |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
412 uoldname)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
413 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
414 (defun calc-remove-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
415 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
416 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
417 (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
|
418 (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
|
419 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
420 (defun calc-extract-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
421 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
422 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
423 (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
|
424 (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
|
425 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
426 ;; 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
|
427 ;; 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
|
428 ;; 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
|
429 (defvar calc-num-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
430 (defvar calc-den-units) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
431 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
432 (defun calc-explain-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
433 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
434 (calc-wrapper |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
435 (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
|
436 (calc-den-units nil)) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
437 (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
|
438 (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
|
439 (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
|
440 (if calc-num-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
441 (if calc-den-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
442 (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
|
443 (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
|
444 (if calc-den-units |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
445 (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
|
446 (message "No units in expression")))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
447 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
448 (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
|
449 (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
|
450 pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
451 (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
|
452 (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
|
453 (if (eq (aref name 0) ?\*) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
454 (setq name (substring name 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
455 (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
|
456 (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
|
457 (while (setq pos (string-match "[ ()]" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
458 (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
|
459 (if (eq (aref name pos) 32) "-" "") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
460 (substring name (1+ pos))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
461 (setq name (concat "(" name ")")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
462 (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
|
463 (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
|
464 (nth 1 expr)) 0) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
465 math-unit-prefixes)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
466 (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
|
467 (not (memq (car u) '(mHg gf)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
468 (concat "-" name) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
469 (downcase name))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
470 (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
|
471 (math-equal-int pow -1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
472 ((or (math-equal-int pow 2) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
473 (math-equal-int pow -2)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
474 (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
|
475 (setq name (concat "Square-" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
476 (setq name (concat name "-squared")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
477 ((or (math-equal-int pow 3) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
478 (math-equal-int pow -3)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
479 (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
|
480 (setq name (concat "Cubic-" name)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
481 (setq name (concat name "-cubed")))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
482 (t |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
483 (setq name (concat name "^" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
484 (math-format-number (math-abs pow)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
485 (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
|
486 (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
|
487 (concat calc-num-units " " name) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
488 name)) |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
489 (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
|
490 (concat calc-den-units " " name) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
491 name)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
492 (cond ((eq (car-safe expr) '*) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
493 (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
|
494 (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
|
495 ((eq (car-safe expr) '/) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
496 (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
|
497 (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
|
498 ((memq (car-safe expr) '(neg + -)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
499 (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
|
500 ((and (eq (car-safe expr) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
501 (math-realp (nth 2 expr))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
502 (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
|
503 (math-mul pow (nth 2 expr)))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
504 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
505 (defun calc-simplify-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
506 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
507 (calc-slow-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
508 (calc-with-default-simplification |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
509 (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
|
510 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
511 (defun calc-view-units-table (n) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
512 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
513 (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
|
514 (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
|
515 (if (and win |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
516 math-units-table |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
517 math-units-table-buffer-valid) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
518 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
519 (bury-buffer (window-buffer win)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
520 (let ((curwin (selected-window))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
521 (select-window win) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
522 (switch-to-buffer nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
523 (select-window curwin))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
524 (math-build-units-table-buffer nil)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
525 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
526 (defun calc-enter-units-table (n) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
527 (interactive "P") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
528 (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
|
529 (math-build-units-table-buffer t) |
65592
1038e6fc7f28
message format spec fixes, commit # 11
Deepak Goel <deego@gnufans.org>
parents:
64325
diff
changeset
|
530 (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
|
531 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
532 (defun calc-define-unit (uname desc) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
533 (interactive "SDefine unit name: \nsDescription: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
534 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
535 (let ((form (calc-top-n 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
536 (unit (assq uname math-additional-units))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
537 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
538 (setq math-additional-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
539 (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
|
540 math-additional-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
541 math-units-table nil)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
542 (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
|
543 (eq (nth 1 form) uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
544 (not (math-equal-int form 1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
545 (math-format-flat-expr form 0))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
546 (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
|
547 desc)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
548 (calc-invalidate-units-table)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
549 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
550 (defun calc-undefine-unit (uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
551 (interactive "SUndefine unit name: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
552 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
553 (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
|
554 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
555 (if (assq uname math-standard-units) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
556 (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
|
557 (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
|
558 (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
|
559 math-units-table nil))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
560 (calc-invalidate-units-table)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
561 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
562 (defun calc-invalidate-units-table () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
563 (setq math-units-table nil) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
564 (let ((buf (get-buffer "*Units Table*"))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
565 (and buf |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
566 (save-excursion |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
567 (set-buffer buf) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
568 (save-excursion |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
569 (goto-char (point-min)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
570 (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
|
571 (let ((inhibit-read-only t)) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
572 (insert "(Obsolete) ")))))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
573 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
574 (defun calc-get-unit-definition (uname) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
575 (interactive "SGet definition for unit: ") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
576 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
577 (math-build-units-table) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
578 (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
|
579 (or unit |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
580 (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
|
581 (let ((msg (nth 2 unit))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
582 (if (stringp msg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
583 (if (string-match "^\\*" msg) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
584 (setq msg (substring msg 1))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
585 (setq msg (symbol-name uname))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
586 (if (nth 1 unit) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
587 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
588 (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
|
589 (message "Derived unit: %s" msg)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
590 (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
|
591 (intern |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
592 (concat "var-" |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
593 (symbol-name uname))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
594 (message "Base unit: %s" msg)))))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
595 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
596 (defun calc-permanent-units () |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
597 (interactive) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
598 (calc-wrapper |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
599 (let (pos) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
600 (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
|
601 calc-settings-file))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
602 (goto-char (point-min)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
603 (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
|
604 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
605 (beginning-of-line) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
606 (setq pos (point)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
607 (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
|
608 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
609 (beginning-of-line) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
610 (forward-line 1) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
611 (delete-region pos (point))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
612 (goto-char (point-max)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
613 (insert "\n\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
614 (forward-char -1)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
615 (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
|
616 (if math-additional-units |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
617 (progn |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
618 (insert "(setq math-additional-units '(\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
619 (let ((list math-additional-units)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
620 (while list |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
621 (insert " (" (symbol-name (car (car list))) " " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
622 (if (nth 1 (car list)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
623 (if (stringp (nth 1 (car list))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
624 (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
|
625 (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
|
626 (nth 1 (car list)) 0))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
627 "nil") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
628 " " |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
629 (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
|
630 ")\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
631 (setq list (cdr list)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
632 (insert "))\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
633 (insert ";;; (no custom units defined)\n")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
634 (insert ";;; End of custom units\n") |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
635 (save-buffer)))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
636 |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
637 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
638 ;; 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
|
639 ;; 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
|
640 ;; 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
|
641 ;; 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
|
642 ;; 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
|
643 (defvar math-cu-unit-list) |
40785 | 644 |
645 (defun math-build-units-table () | |
646 (or math-units-table | |
647 (let* ((combined-units (append math-additional-units | |
648 math-standard-units)) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
649 (math-cu-unit-list (mapcar 'car combined-units)) |
40785 | 650 tab) |
651 (message "Building units table...") | |
652 (setq math-units-table-buffer-valid nil) | |
653 (setq tab (mapcar (function | |
654 (lambda (x) | |
655 (list (car x) | |
656 (and (nth 1 x) | |
657 (if (stringp (nth 1 x)) | |
658 (let ((exp (math-read-plain-expr | |
659 (nth 1 x)))) | |
660 (if (eq (car-safe exp) 'error) | |
661 (error "Format error in definition of %s in units table: %s" | |
662 (car x) (nth 2 exp)) | |
663 exp)) | |
664 (nth 1 x))) | |
665 (nth 2 x) | |
666 (nth 3 x) | |
667 (and (not (nth 1 x)) | |
668 (list (cons (car x) 1)))))) | |
669 combined-units)) | |
670 (let ((math-units-table tab)) | |
671 (mapcar 'math-find-base-units tab)) | |
672 (message "Building units table...done") | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
673 (setq math-units-table tab)))) |
40785 | 674 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
675 ;; 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
|
676 ;; 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
|
677 ;; 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
|
678 (defvar math-fbu-base) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
679 (defvar math-fbu-entry) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
680 |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
681 (defun math-find-base-units (math-fbu-entry) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
682 (if (eq (nth 4 math-fbu-entry) 'boom) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
683 (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
|
684 (or (nth 4 math-fbu-entry) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
685 (let (math-fbu-base) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
686 (setcar (nthcdr 4 math-fbu-entry) 'boom) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
687 (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
|
688 '(or math-fbu-base |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
689 (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
|
690 (while (eq (cdr (car math-fbu-base)) 0) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
691 (setq math-fbu-base (cdr math-fbu-base))) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
692 (let ((b math-fbu-base)) |
40785 | 693 (while (cdr b) |
694 (if (eq (cdr (car (cdr b))) 0) | |
695 (setcdr b (cdr (cdr b))) | |
696 (setq b (cdr b))))) | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
697 (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
|
698 (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
|
699 math-fbu-base))) |
40785 | 700 |
701 (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
|
702 (memq (car b) (cdr (memq (car a) math-cu-unit-list)))) |
40785 | 703 |
704 (defun math-find-base-units-rec (expr pow) | |
705 (let ((u (math-check-unit-name expr))) | |
706 (cond (u | |
707 (let ((ulist (math-find-base-units u))) | |
708 (while ulist | |
709 (let ((p (* (cdr (car ulist)) pow)) | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
710 (old (assq (car (car ulist)) math-fbu-base))) |
40785 | 711 (if old |
712 (setcdr old (+ (cdr old) p)) | |
58511
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
713 (setq math-fbu-base |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
714 (cons (cons (car (car ulist)) p) math-fbu-base)))) |
40785 | 715 (setq ulist (cdr ulist))))) |
716 ((math-scalarp expr)) | |
717 ((and (eq (car expr) '^) | |
718 (integerp (nth 2 expr))) | |
719 (math-find-base-units-rec (nth 1 expr) (* pow (nth 2 expr)))) | |
720 ((eq (car expr) '*) | |
721 (math-find-base-units-rec (nth 1 expr) pow) | |
722 (math-find-base-units-rec (nth 2 expr) pow)) | |
723 ((eq (car expr) '/) | |
724 (math-find-base-units-rec (nth 1 expr) pow) | |
725 (math-find-base-units-rec (nth 2 expr) (- pow))) | |
726 ((eq (car expr) 'neg) | |
727 (math-find-base-units-rec (nth 1 expr) pow)) | |
728 ((eq (car expr) '+) | |
729 (math-find-base-units-rec (nth 1 expr) pow)) | |
730 ((eq (car expr) 'var) | |
731 (or (eq (nth 1 expr) 'pi) | |
732 (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
|
733 (nth 1 expr) (car math-fbu-entry)))) |
0a3797785946
Finish making previous changes.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58508
diff
changeset
|
734 (t (error "Malformed defining expression for unit %s" (car math-fbu-entry)))))) |
40785 | 735 |
736 | |
737 (defun math-units-in-expr-p (expr sub-exprs) | |
738 (and (consp expr) | |
739 (if (eq (car expr) 'var) | |
740 (math-check-unit-name expr) | |
741 (and (or sub-exprs | |
742 (memq (car expr) '(* / ^))) | |
743 (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
|
744 (math-units-in-expr-p (nth 2 expr) sub-exprs)))))) |
40785 | 745 |
746 (defun math-only-units-in-expr-p (expr) | |
747 (and (consp expr) | |
748 (if (eq (car expr) 'var) | |
749 (math-check-unit-name expr) | |
750 (if (memq (car expr) '(* /)) | |
751 (and (math-only-units-in-expr-p (nth 1 expr)) | |
752 (math-only-units-in-expr-p (nth 2 expr))) | |
753 (and (eq (car expr) '^) | |
754 (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
|
755 (math-realp (nth 2 expr)))))))) |
40785 | 756 |
757 (defun math-single-units-in-expr-p (expr) | |
758 (cond ((math-scalarp expr) nil) | |
759 ((eq (car expr) 'var) | |
760 (math-check-unit-name expr)) | |
761 ((eq (car expr) '*) | |
762 (let ((u1 (math-single-units-in-expr-p (nth 1 expr))) | |
763 (u2 (math-single-units-in-expr-p (nth 2 expr)))) | |
764 (or (and u1 u2 'wrong) | |
765 u1 | |
766 u2))) | |
767 ((eq (car expr) '/) | |
768 (if (math-units-in-expr-p (nth 2 expr) nil) | |
769 'wrong | |
770 (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
|
771 (t 'wrong))) |
40785 | 772 |
773 (defun math-check-unit-name (v) | |
774 (and (eq (car-safe v) 'var) | |
775 (or (assq (nth 1 v) (or math-units-table (math-build-units-table))) | |
776 (let ((name (symbol-name (nth 1 v)))) | |
777 (and (> (length name) 1) | |
778 (assq (aref name 0) math-unit-prefixes) | |
779 (or (assq (intern (substring name 1)) math-units-table) | |
780 (and (eq (aref name 0) ?M) | |
781 (> (length name) 3) | |
782 (eq (aref name 1) ?e) | |
783 (eq (aref name 2) ?g) | |
784 (assq (intern (substring name 3)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
785 math-units-table)))))))) |
40785 | 786 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
787 ;; 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
|
788 ;; 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
|
789 ;; math-to-standard-units. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
790 (defvar math-which-standard) |
40785 | 791 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
792 (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
|
793 (math-to-standard-rec expr)) |
40785 | 794 |
795 (defun math-to-standard-rec (expr) | |
796 (if (eq (car-safe expr) 'var) | |
797 (let ((u (math-check-unit-name expr)) | |
798 (base (nth 1 expr))) | |
799 (if u | |
800 (progn | |
801 (if (nth 1 u) | |
802 (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
|
803 (let ((st (assq (car u) math-which-standard))) |
40785 | 804 (if st |
805 (setq expr (nth 1 st)) | |
806 (setq expr (list 'var (car u) | |
807 (intern (concat "var-" | |
808 (symbol-name | |
809 (car u))))))))) | |
810 (or (null u) | |
811 (eq base (car u)) | |
812 (setq expr (list '* | |
813 (nth 1 (assq (aref (symbol-name base) 0) | |
814 math-unit-prefixes)) | |
815 expr))) | |
816 expr) | |
817 (if (eq base 'pi) | |
818 (math-pi) | |
819 expr))) | |
820 (if (Math-primp expr) | |
821 expr | |
822 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
823 (mapcar 'math-to-standard-rec (cdr expr)))))) |
40785 | 824 |
825 (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
|
826 (setq expr (math-simplify-units expr)) |
40785 | 827 (if ulist |
828 (let ((new 0) | |
829 value) | |
830 (or (math-numberp expr) | |
831 (error "Incompatible units")) | |
832 (while (cdr ulist) | |
833 (setq value (math-div expr (nth 1 (car ulist))) | |
834 value (math-floor (let ((calc-internal-prec | |
835 (1- calc-internal-prec))) | |
836 (math-normalize value))) | |
837 new (math-add new (math-mul value (car (car ulist)))) | |
838 expr (math-sub expr (math-mul value (nth 1 (car ulist)))) | |
839 ulist (cdr ulist))) | |
840 (math-add new (math-mul (math-div expr (nth 1 (car ulist))) | |
841 (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
|
842 (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
|
843 expr |
f3c30d255a4d
(math-apply-units): Change the places in which units are simplified.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62565
diff
changeset
|
844 (math-simplify-units (list '* expr units))))) |
40785 | 845 |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
846 (defvar math-decompose-units-cache nil) |
40785 | 847 (defun math-decompose-units (units) |
848 (let ((u (math-check-unit-name units))) | |
849 (and u (eq (car-safe (nth 1 u)) '+) | |
850 (setq units (nth 1 u)))) | |
851 (setq units (calcFunc-expand units)) | |
852 (and (eq (car-safe units) '+) | |
853 (let ((entry (list units calc-internal-prec calc-prefer-frac))) | |
854 (or (equal entry (car math-decompose-units-cache)) | |
855 (let ((ulist nil) | |
856 (utemp units) | |
857 qty unit) | |
858 (while (eq (car-safe utemp) '+) | |
859 (setq ulist (cons (math-decompose-unit-part (nth 2 utemp)) | |
860 ulist) | |
861 utemp (nth 1 utemp))) | |
862 (setq ulist (cons (math-decompose-unit-part utemp) ulist) | |
863 utemp ulist) | |
864 (while (setq utemp (cdr utemp)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
865 (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
|
866 (error "Inconsistent units in sum"))) |
40785 | 867 (setq math-decompose-units-cache |
868 (cons entry | |
869 (sort ulist | |
870 (function | |
871 (lambda (x y) | |
872 (not (Math-lessp (nth 1 x) | |
873 (nth 1 y)))))))))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
874 (cdr math-decompose-units-cache)))) |
40785 | 875 |
876 (defun math-decompose-unit-part (unit) | |
877 (cons unit | |
878 (math-is-multiple (math-simplify-units (math-to-standard-units | |
879 unit nil)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
880 t))) |
40785 | 881 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
882 ;; 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
|
883 ;; 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
|
884 ;; math-find-compatible-unit. |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
885 (defvar math-fcu-u) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
886 |
40785 | 887 (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
|
888 (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
|
889 (if math-fcu-u |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
890 (math-find-compatible-unit-rec expr 1)))) |
40785 | 891 |
892 (defun math-find-compatible-unit-rec (expr pow) | |
893 (cond ((eq (car-safe expr) '*) | |
894 (or (math-find-compatible-unit-rec (nth 1 expr) pow) | |
895 (math-find-compatible-unit-rec (nth 2 expr) pow))) | |
896 ((eq (car-safe expr) '/) | |
897 (or (math-find-compatible-unit-rec (nth 1 expr) pow) | |
898 (math-find-compatible-unit-rec (nth 2 expr) (- pow)))) | |
899 ((and (eq (car-safe expr) '^) | |
900 (integerp (nth 2 expr))) | |
901 (math-find-compatible-unit-rec (nth 1 expr) (* pow (nth 2 expr)))) | |
902 (t | |
903 (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
|
904 (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
|
905 (cons expr pow)))))) |
40785 | 906 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
907 ;; 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
|
908 ;; 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
|
909 ;; 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
|
910 (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
|
911 (defvar math-cu-pure) |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
912 |
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
913 (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
|
914 (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
|
915 (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
|
916 (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
|
917 (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
|
918 (setq math-cu-new-units (nth 1 unew))))) |
40785 | 919 (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
|
920 (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
|
921 (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
|
922 (math-cu-unit-list nil) |
40785 | 923 (math-combining-units nil)) |
924 (if compat | |
925 (math-simplify-units | |
926 (math-mul (math-mul (math-simplify-units | |
927 (math-div expr (math-pow (car compat) | |
928 (cdr compat)))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
929 (math-pow math-cu-new-units (cdr compat))) |
40785 | 930 (math-simplify-units |
931 (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
|
932 (math-pow (math-div (car compat) math-cu-new-units) |
40785 | 933 (cdr compat)) |
934 nil)))) | |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
935 (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
|
936 (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
|
937 (when (eq (car-safe expr) '+) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
938 (setq expr (math-simplify-units expr))) |
40785 | 939 (if (math-units-in-expr-p expr t) |
940 (math-convert-units-rec expr) | |
941 (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
|
942 (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
|
943 math-cu-new-units math-cu-unit-list math-cu-pure)))))) |
40785 | 944 |
945 (defun math-convert-units-rec (expr) | |
946 (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
|
947 (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
|
948 (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
|
949 math-cu-new-units math-cu-unit-list math-cu-pure) |
40785 | 950 (if (Math-primp expr) |
951 expr | |
952 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
953 (mapcar 'math-convert-units-rec (cdr expr)))))) |
40785 | 954 |
955 (defun math-convert-temperature (expr old new &optional pure) | |
956 (let* ((units (math-single-units-in-expr-p expr)) | |
957 (uold (if old | |
958 (if (or (null units) | |
959 (equal (nth 1 old) (car units))) | |
960 (math-check-unit-name old) | |
961 (error "Inconsistent temperature units")) | |
962 units)) | |
963 (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
|
964 (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
|
965 (error "Not a valid temperature unit")) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
966 (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
|
967 (error "Not a pure temperature expression")) |
40785 | 968 (let ((v (car uold))) |
969 (setq expr (list '/ expr (list 'var v | |
970 (intern (concat "var-" | |
971 (symbol-name v))))))) | |
972 (or (eq (nth 3 uold) (nth 3 unew)) | |
973 (cond ((eq (nth 3 uold) 'K) | |
974 (setq expr (list '- expr '(float 27315 -2))) | |
975 (if (eq (nth 3 unew) 'F) | |
976 (setq expr (list '+ (list '* expr '(frac 9 5)) 32)))) | |
977 ((eq (nth 3 uold) 'C) | |
978 (if (eq (nth 3 unew) 'F) | |
979 (setq expr (list '+ (list '* expr '(frac 9 5)) 32)) | |
980 (setq expr (list '+ expr '(float 27315 -2))))) | |
981 (t | |
982 (setq expr (list '* (list '- expr 32) '(frac 5 9))) | |
983 (if (eq (nth 3 unew) 'K) | |
984 (setq expr (list '+ expr '(float 27315 -2))))))) | |
985 (if pure | |
986 expr | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
987 (list '* expr new)))) |
40785 | 988 |
989 | |
990 | |
991 (defun math-simplify-units (a) | |
992 (let ((math-simplifying-units t) | |
993 (calc-matrix-mode 'scalar)) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
994 (math-simplify a))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
995 (defalias 'calcFunc-usimplify 'math-simplify-units) |
40785 | 996 |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
997 ;; 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
|
998 ;; 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
|
999 (defvar math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1000 |
40785 | 1001 (math-defsimplify (+ -) |
1002 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1003 (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
|
1004 (let* ((units (math-extract-units (nth 1 math-simplify-expr))) |
40785 | 1005 (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
|
1006 (list '/ (nth 2 math-simplify-expr) units) nil)))) |
40785 | 1007 (if (math-units-in-expr-p ratio nil) |
1008 (progn | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1009 (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
|
1010 math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1011 (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
|
1012 (if (eq (car math-simplify-expr) '-) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1013 (math-neg ratio) ratio)) |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1014 units))))) |
40785 | 1015 |
1016 (math-defsimplify * | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1017 (math-simplify-units-prod)) |
40785 | 1018 |
1019 (defun math-simplify-units-prod () | |
1020 (and math-simplifying-units | |
1021 calc-autorange-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1022 (Math-realp (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1023 (let* ((num (math-float (nth 1 math-simplify-expr))) |
40785 | 1024 (xpon (calcFunc-xpon num)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1025 (unitp (cdr (cdr math-simplify-expr))) |
40785 | 1026 (unit (car unitp)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1027 (pow (if (eq (car math-simplify-expr) '*) 1 -1)) |
40785 | 1028 u) |
1029 (and (eq (car-safe unit) '*) | |
1030 (setq unitp (cdr unit) | |
1031 unit (car unitp))) | |
1032 (and (eq (car-safe unit) '^) | |
1033 (integerp (nth 2 unit)) | |
1034 (setq pow (* pow (nth 2 unit)) | |
1035 unitp (cdr unit) | |
1036 unit (car unitp))) | |
1037 (and (setq u (math-check-unit-name unit)) | |
1038 (integerp xpon) | |
1039 (or (< xpon 0) | |
1040 (>= xpon (if (eq (car u) 'm) 1 3))) | |
1041 (let* ((uxpon 0) | |
1042 (pref (if (< pow 0) | |
1043 (reverse math-unit-prefixes) | |
1044 math-unit-prefixes)) | |
1045 (p pref) | |
1046 pxpon pname) | |
1047 (or (eq (car u) (nth 1 unit)) | |
1048 (setq uxpon (* pow | |
1049 (nth 2 (nth 1 (assq | |
1050 (aref (symbol-name | |
1051 (nth 1 unit)) 0) | |
1052 math-unit-prefixes)))))) | |
1053 (setq xpon (+ xpon uxpon)) | |
1054 (while (and p | |
1055 (or (memq (car (car p)) '(?d ?D ?h ?H)) | |
1056 (and (eq (car (car p)) ?c) | |
1057 (not (eq (car u) 'm))) | |
1058 (< xpon (setq pxpon (* (nth 2 (nth 1 (car p))) | |
1059 pow))) | |
1060 (progn | |
1061 (setq pname (math-build-var-name | |
1062 (if (eq (car (car p)) 0) | |
1063 (car u) | |
1064 (concat (char-to-string | |
1065 (car (car p))) | |
1066 (symbol-name | |
1067 (car u)))))) | |
1068 (and (/= (car (car p)) 0) | |
1069 (assq (nth 1 pname) | |
1070 math-units-table))))) | |
1071 (setq p (cdr p))) | |
1072 (and p | |
1073 (/= pxpon uxpon) | |
1074 (or (not (eq p pref)) | |
1075 (< xpon (+ pxpon (* (math-abs pow) 3)))) | |
1076 (progn | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1077 (setcar (cdr math-simplify-expr) |
40785 | 1078 (let ((calc-prefer-frac nil)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1079 (calcFunc-scf (nth 1 math-simplify-expr) |
40785 | 1080 (- uxpon pxpon)))) |
1081 (setcar unitp pname) | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1082 math-simplify-expr))))))) |
40785 | 1083 |
58508
589dc235628a
(calc-convert-units): Make units a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58303
diff
changeset
|
1084 (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
|
1085 |
40785 | 1086 (math-defsimplify / |
1087 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1088 (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
|
1089 (math-try-cancel-units 0) |
40785 | 1090 n nn) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1091 (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
|
1092 (cdr (nth 2 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1093 (nthcdr 2 math-simplify-expr))) |
40785 | 1094 (if (math-realp (car n)) |
1095 (progn | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1096 (setcar (cdr math-simplify-expr) (math-mul (nth 1 math-simplify-expr) |
40785 | 1097 (let ((calc-prefer-frac nil)) |
1098 (math-div 1 (car n))))) | |
1099 (setcar n 1))) | |
1100 (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
|
1101 (math-simplify-units-divisor (cdr n) (cdr (cdr math-simplify-expr))) |
40785 | 1102 (setq np (cdr (cdr n)))) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1103 (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
|
1104 (if (eq math-try-cancel-units 0) |
40785 | 1105 (let* ((math-simplifying-units nil) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1106 (base (math-simplify |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1107 (math-to-standard-units math-simplify-expr nil)))) |
40785 | 1108 (if (Math-numberp base) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1109 (setq math-simplify-expr base)))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1110 (if (eq (car-safe math-simplify-expr) '/) |
40785 | 1111 (math-simplify-units-prod)) |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1112 math-simplify-expr))) |
40785 | 1113 |
1114 (defun math-simplify-units-divisor (np dp) | |
1115 (let ((n (car np)) | |
1116 d dd temp) | |
1117 (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
|
1118 (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
|
1119 (setcar np (setq n temp)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1120 (setcar (cdr d) 1)) |
40785 | 1121 (setq dp (cdr (cdr d)))) |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1122 (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
|
1123 (setcar np (setq n temp)) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1124 (setcar dp 1)))) |
40785 | 1125 |
1126 ;; Simplify, e.g., "in / cm" to "2.54" in a units expression. | |
1127 (defun math-simplify-units-quotient (n d) | |
1128 (let ((pow1 1) | |
1129 (pow2 1)) | |
41269
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1130 (when (and (eq (car-safe n) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1131 (integerp (nth 2 n))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1132 (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
|
1133 (when (and (eq (car-safe d) '^) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1134 (integerp (nth 2 d))) |
8b4a880d7759
(calcFunc-usimplify): Add missing quote to defalias argument.
Colin Walters <walters@gnu.org>
parents:
41046
diff
changeset
|
1135 (setq pow2 (nth 2 d) d (nth 1 d))) |
40785 | 1136 (let ((un (math-check-unit-name n)) |
1137 (ud (math-check-unit-name d))) | |
1138 (and un ud | |
1139 (if (and (equal (nth 4 un) (nth 4 ud)) | |
1140 (eq pow1 pow2)) | |
1141 (math-to-standard-units (list '/ n d) nil) | |
1142 (let (ud1) | |
1143 (setq un (nth 4 un) | |
1144 ud (nth 4 ud)) | |
1145 (while un | |
1146 (setq ud1 ud) | |
1147 (while ud1 | |
1148 (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
|
1149 (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
|
1150 (+ math-try-cancel-units |
40785 | 1151 (- (* (cdr (car un)) pow1) |
1152 (* (cdr (car ud)) pow2))))) | |
1153 (setq ud1 (cdr ud1))) | |
1154 (setq un (cdr un))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1155 nil)))))) |
40785 | 1156 |
1157 (math-defsimplify ^ | |
1158 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1159 (math-realp (nth 2 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1160 (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
|
1161 (list (car (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1162 (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
|
1163 (nth 2 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1164 (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
|
1165 (nth 2 math-simplify-expr))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1166 (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
|
1167 (nth 2 math-simplify-expr))))) |
40785 | 1168 |
1169 (math-defsimplify calcFunc-sqrt | |
1170 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1171 (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
|
1172 (list (car (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1173 (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
|
1174 (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
|
1175 (math-simplify-units-pow (nth 1 math-simplify-expr) '(frac 1 2))))) |
40785 | 1176 |
1177 (math-defsimplify (calcFunc-floor | |
1178 calcFunc-ceil | |
1179 calcFunc-round | |
1180 calcFunc-rounde | |
1181 calcFunc-roundu | |
1182 calcFunc-trunc | |
1183 calcFunc-float | |
1184 calcFunc-frac | |
1185 calcFunc-abs | |
1186 calcFunc-clean) | |
1187 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1188 (= (length math-simplify-expr) 2) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1189 (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
|
1190 (nth 1 math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1191 (if (and (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
40785 | 1192 (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
|
1193 (nth 1 (nth 1 math-simplify-expr))) |
40785 | 1194 (math-only-units-in-expr-p |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1195 (nth 2 (nth 1 math-simplify-expr))))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1196 (list (car (nth 1 math-simplify-expr)) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1197 (cons (car math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1198 (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
|
1199 (cdr (cdr math-simplify-expr)))) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1200 (cons (car math-simplify-expr) |
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1201 (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
|
1202 (cdr (cdr math-simplify-expr))))))))) |
40785 | 1203 |
1204 (defun math-simplify-units-pow (a pow) | |
1205 (if (and (eq (car-safe a) '^) | |
1206 (math-check-unit-name (nth 1 a)) | |
1207 (math-realp (nth 2 a))) | |
1208 (list '^ (nth 1 a) (math-mul pow (nth 2 a))) | |
1209 (let* ((u (math-check-unit-name a)) | |
1210 (pf (math-to-simple-fraction pow)) | |
1211 (d (and (eq (car-safe pf) 'frac) (nth 2 pf)))) | |
1212 (and u d | |
1213 (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
|
1214 (list '^ (math-to-standard-units a nil) pow))))) |
40785 | 1215 |
1216 | |
1217 (defun math-units-are-multiple (u n) | |
1218 (setq u (nth 4 u)) | |
1219 (while (and u (= (% (cdr (car u)) n) 0)) | |
1220 (setq u (cdr u))) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1221 (null u)) |
40785 | 1222 |
1223 (math-defsimplify calcFunc-sin | |
1224 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1225 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
40785 | 1226 (let ((rad (math-simplify-units |
1227 (math-evaluate-expr | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1228 (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
40785 | 1229 (calc-angle-mode 'rad)) |
1230 (and (eq (car-safe rad) '*) | |
1231 (math-realp (nth 1 rad)) | |
1232 (eq (car-safe (nth 2 rad)) 'var) | |
1233 (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
|
1234 (list 'calcFunc-sin (nth 1 rad)))))) |
40785 | 1235 |
1236 (math-defsimplify calcFunc-cos | |
1237 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1238 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
40785 | 1239 (let ((rad (math-simplify-units |
1240 (math-evaluate-expr | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1241 (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
40785 | 1242 (calc-angle-mode 'rad)) |
1243 (and (eq (car-safe rad) '*) | |
1244 (math-realp (nth 1 rad)) | |
1245 (eq (car-safe (nth 2 rad)) 'var) | |
1246 (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
|
1247 (list 'calcFunc-cos (nth 1 rad)))))) |
40785 | 1248 |
1249 (math-defsimplify calcFunc-tan | |
1250 (and math-simplifying-units | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1251 (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
40785 | 1252 (let ((rad (math-simplify-units |
1253 (math-evaluate-expr | |
58303
6ae80af2f94b
(math-simplify-expr): Declared it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57130
diff
changeset
|
1254 (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
40785 | 1255 (calc-angle-mode 'rad)) |
1256 (and (eq (car-safe rad) '*) | |
1257 (math-realp (nth 1 rad)) | |
1258 (eq (car-safe (nth 2 rad)) 'var) | |
1259 (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
|
1260 (list 'calcFunc-tan (nth 1 rad)))))) |
40785 | 1261 |
60082
1697c06499c8
Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59394
diff
changeset
|
1262 (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
|
1263 (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
|
1264 (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
|
1265 (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
|
1266 (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
|
1267 (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
|
1268 (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
|
1269 (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
|
1270 (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
|
1271 (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
|
1272 (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
|
1273 (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
|
1274 |
1697c06499c8
Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59394
diff
changeset
|
1275 (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
|
1276 (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
|
1277 (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
|
1278 (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
|
1279 (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
|
1280 (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
|
1281 (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
|
1282 (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
|
1283 (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
|
1284 (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
|
1285 (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
|
1286 (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
|
1287 |
1697c06499c8
Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59394
diff
changeset
|
1288 (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
|
1289 (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
|
1290 (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
|
1291 (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
|
1292 (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
|
1293 (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
|
1294 (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
|
1295 (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
|
1296 (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
|
1297 (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
|
1298 (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
|
1299 (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
|
1300 |
40785 | 1301 |
1302 (defun math-remove-units (expr) | |
1303 (if (math-check-unit-name expr) | |
1304 1 | |
1305 (if (Math-primp expr) | |
1306 expr | |
1307 (cons (car expr) | |
41046
14b73d89514a
(calcFunc-unsimplify): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1308 (mapcar 'math-remove-units (cdr expr)))))) |
40785 | 1309 |
1310 (defun math-extract-units (expr) | |
1311 (if (memq (car-safe expr) '(* /)) | |
1312 (cons (car expr) | |
1313 (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
|
1314 (if (math-check-unit-name expr) expr 1))) |
40785 | 1315 |
1316 (defun math-build-units-table-buffer (enter-buffer) | |
1317 (if (not (and math-units-table math-units-table-buffer-valid | |
1318 (get-buffer "*Units Table*"))) | |
1319 (let ((buf (get-buffer-create "*Units Table*")) | |
1320 (uptr (math-build-units-table)) | |
1321 (calc-language (if (eq calc-language 'big) nil calc-language)) | |
1322 (calc-float-format '(float 0)) | |
1323 (calc-group-digits nil) | |
1324 (calc-number-radix 10) | |
1325 (calc-point-char ".") | |
1326 (std nil) | |
1327 u name shadowed) | |
1328 (save-excursion | |
1329 (message "Formatting units table...") | |
1330 (set-buffer buf) | |
62565
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1331 (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
|
1332 (erase-buffer) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1333 (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
|
1334 (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
|
1335 (while uptr |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1336 (setq u (car uptr) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1337 name (nth 2 u)) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1338 (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
|
1339 (setq std t)) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1340 (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
|
1341 (when (and name |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1342 (> (length name) 1) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1343 (eq (aref name 0) ?\*)) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1344 (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
|
1345 (insert "\n")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1346 (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
|
1347 (insert " ") |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1348 (and shadowed (insert "(")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1349 (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
|
1350 (and shadowed (insert ")")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1351 (if (nth 3 u) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1352 (progn |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1353 (indent-to 10) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1354 (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
|
1355 (or std |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1356 (progn |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1357 (indent-to 10) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1358 (insert "U")))) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1359 (indent-to 14) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1360 (and shadowed (insert "(")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1361 (if (nth 1 u) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1362 (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
|
1363 (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
|
1364 (and shadowed (insert ")")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1365 (indent-to 41) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1366 (insert " ") |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1367 (when name |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1368 (insert name)) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1369 (if shadowed |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1370 (insert " (redefined above)") |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1371 (unless (nth 1 u) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1372 (insert " (base unit)"))) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1373 (insert "\n") |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1374 (setq uptr (cdr uptr))) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1375 (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
|
1376 (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
|
1377 (while uptr |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1378 (setq u (car uptr)) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1379 (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
|
1380 (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
|
1381 (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
|
1382 " ") |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1383 (insert " ")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1384 (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
|
1385 (indent-to 15) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1386 (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
|
1387 (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
|
1388 (insert "\n")) |
2b285bf6f228
(calc-invalidate-units-table): Use inhibit-read-only.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61412
diff
changeset
|
1389 (view-mode) |
40785 | 1390 (message "Formatting units table...done")) |
1391 (setq math-units-table-buffer-valid t) | |
1392 (let ((oldbuf (current-buffer))) | |
1393 (set-buffer buf) | |
1394 (goto-char (point-min)) | |
1395 (set-buffer oldbuf)) | |
1396 (if enter-buffer | |
1397 (pop-to-buffer buf) | |
1398 (display-buffer buf))) | |
1399 (if enter-buffer | |
1400 (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
|
1401 (display-buffer (get-buffer "*Units Table*"))))) |
40785 | 1402 |
58677
5ef7cf7f3b8f
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58511
diff
changeset
|
1403 (provide 'calc-units) |
5ef7cf7f3b8f
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58511
diff
changeset
|
1404 |
45291
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1405 ;; Local Variables: |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1406 ;; coding: iso-latin-1 |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1407 ;; End: |
01f46f9c1fa0
(math-standard-units): Update from CODATA.
Colin Walters <walters@gnu.org>
parents:
41269
diff
changeset
|
1408 |
52401 | 1409 ;;; 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
|
1410 ;;; calc-units.el ends here |