annotate lisp/calc/calc-units.el @ 42597:255b72a74a90

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