diff options
| author | Jay Belanger | 2004-11-17 19:23:41 +0000 |
|---|---|---|
| committer | Jay Belanger | 2004-11-17 19:23:41 +0000 |
| commit | f095c6c9dbcbdf6bb21a623571fc4c4be09d7b98 (patch) | |
| tree | c92bc6f6a5985dc8d29e5e997d40e940014b8208 /lisp | |
| parent | e10300728dfe90ef55135dc309c9618db8f88d4b (diff) | |
| download | emacs-f095c6c9dbcbdf6bb21a623571fc4c4be09d7b98.tar.gz emacs-f095c6c9dbcbdf6bb21a623571fc4c4be09d7b98.zip | |
(math-simplify-expr): Declared it.
Replaced argument expr in all calls of math-defsimplify by
math-simplify-expr.
(math-simplify-units-prod): Replaced variable expr by declared
variable math-simplify-expr.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/calc/calc-units.el | 122 |
1 files changed, 65 insertions, 57 deletions
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el index 025b208120b..f0c29134799 100644 --- a/lisp/calc/calc-units.el +++ b/lisp/calc/calc-units.el | |||
| @@ -3,8 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: David Gillespie <daveg@synaptics.com> | 5 | ;; Author: David Gillespie <daveg@synaptics.com> |
| 6 | ;; Maintainers: D. Goel <deego@gnufans.org> | 6 | ;; Maintainer: Jay Belanger <belanger@truman.edu> |
| 7 | ;; Colin Walters <walters@debian.org> | ||
| 8 | 7 | ||
| 9 | ;; This file is part of GNU Emacs. | 8 | ;; This file is part of GNU Emacs. |
| 10 | 9 | ||
| @@ -940,18 +939,23 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 940 | (math-simplify a))) | 939 | (math-simplify a))) |
| 941 | (defalias 'calcFunc-usimplify 'math-simplify-units) | 940 | (defalias 'calcFunc-usimplify 'math-simplify-units) |
| 942 | 941 | ||
| 942 | ;; The function created by math-defsimplify uses the variable | ||
| 943 | ;; math-simplify-expr, and so is used by functions in math-defsimplify | ||
| 944 | (defvar math-simplify-expr) | ||
| 945 | |||
| 943 | (math-defsimplify (+ -) | 946 | (math-defsimplify (+ -) |
| 944 | (and math-simplifying-units | 947 | (and math-simplifying-units |
| 945 | (math-units-in-expr-p (nth 1 expr) nil) | 948 | (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
| 946 | (let* ((units (math-extract-units (nth 1 expr))) | 949 | (let* ((units (math-extract-units (nth 1 math-simplify-expr))) |
| 947 | (ratio (math-simplify (math-to-standard-units | 950 | (ratio (math-simplify (math-to-standard-units |
| 948 | (list '/ (nth 2 expr) units) nil)))) | 951 | (list '/ (nth 2 math-simplify-expr) units) nil)))) |
| 949 | (if (math-units-in-expr-p ratio nil) | 952 | (if (math-units-in-expr-p ratio nil) |
| 950 | (progn | 953 | (progn |
| 951 | (calc-record-why "*Inconsistent units" expr) | 954 | (calc-record-why "*Inconsistent units" math-simplify-expr) |
| 952 | expr) | 955 | math-simplify-expr) |
| 953 | (list '* (math-add (math-remove-units (nth 1 expr)) | 956 | (list '* (math-add (math-remove-units (nth 1 math-simplify-expr)) |
| 954 | (if (eq (car expr) '-) (math-neg ratio) ratio)) | 957 | (if (eq (car math-simplify-expr) '-) |
| 958 | (math-neg ratio) ratio)) | ||
| 955 | units))))) | 959 | units))))) |
| 956 | 960 | ||
| 957 | (math-defsimplify * | 961 | (math-defsimplify * |
| @@ -960,12 +964,12 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 960 | (defun math-simplify-units-prod () | 964 | (defun math-simplify-units-prod () |
| 961 | (and math-simplifying-units | 965 | (and math-simplifying-units |
| 962 | calc-autorange-units | 966 | calc-autorange-units |
| 963 | (Math-realp (nth 1 expr)) | 967 | (Math-realp (nth 1 math-simplify-expr)) |
| 964 | (let* ((num (math-float (nth 1 expr))) | 968 | (let* ((num (math-float (nth 1 math-simplify-expr))) |
| 965 | (xpon (calcFunc-xpon num)) | 969 | (xpon (calcFunc-xpon num)) |
| 966 | (unitp (cdr (cdr expr))) | 970 | (unitp (cdr (cdr math-simplify-expr))) |
| 967 | (unit (car unitp)) | 971 | (unit (car unitp)) |
| 968 | (pow (if (eq (car expr) '*) 1 -1)) | 972 | (pow (if (eq (car math-simplify-expr) '*) 1 -1)) |
| 969 | u) | 973 | u) |
| 970 | (and (eq (car-safe unit) '*) | 974 | (and (eq (car-safe unit) '*) |
| 971 | (setq unitp (cdr unit) | 975 | (setq unitp (cdr unit) |
| @@ -1015,39 +1019,40 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 1015 | (or (not (eq p pref)) | 1019 | (or (not (eq p pref)) |
| 1016 | (< xpon (+ pxpon (* (math-abs pow) 3)))) | 1020 | (< xpon (+ pxpon (* (math-abs pow) 3)))) |
| 1017 | (progn | 1021 | (progn |
| 1018 | (setcar (cdr expr) | 1022 | (setcar (cdr math-simplify-expr) |
| 1019 | (let ((calc-prefer-frac nil)) | 1023 | (let ((calc-prefer-frac nil)) |
| 1020 | (calcFunc-scf (nth 1 expr) | 1024 | (calcFunc-scf (nth 1 math-simplify-expr) |
| 1021 | (- uxpon pxpon)))) | 1025 | (- uxpon pxpon)))) |
| 1022 | (setcar unitp pname) | 1026 | (setcar unitp pname) |
| 1023 | expr))))))) | 1027 | math-simplify-expr))))))) |
| 1024 | 1028 | ||
| 1025 | (math-defsimplify / | 1029 | (math-defsimplify / |
| 1026 | (and math-simplifying-units | 1030 | (and math-simplifying-units |
| 1027 | (let ((np (cdr expr)) | 1031 | (let ((np (cdr math-simplify-expr)) |
| 1028 | (try-cancel-units 0) | 1032 | (try-cancel-units 0) |
| 1029 | n nn) | 1033 | n nn) |
| 1030 | (setq n (if (eq (car-safe (nth 2 expr)) '*) | 1034 | (setq n (if (eq (car-safe (nth 2 math-simplify-expr)) '*) |
| 1031 | (cdr (nth 2 expr)) | 1035 | (cdr (nth 2 math-simplify-expr)) |
| 1032 | (nthcdr 2 expr))) | 1036 | (nthcdr 2 math-simplify-expr))) |
| 1033 | (if (math-realp (car n)) | 1037 | (if (math-realp (car n)) |
| 1034 | (progn | 1038 | (progn |
| 1035 | (setcar (cdr expr) (math-mul (nth 1 expr) | 1039 | (setcar (cdr math-simplify-expr) (math-mul (nth 1 math-simplify-expr) |
| 1036 | (let ((calc-prefer-frac nil)) | 1040 | (let ((calc-prefer-frac nil)) |
| 1037 | (math-div 1 (car n))))) | 1041 | (math-div 1 (car n))))) |
| 1038 | (setcar n 1))) | 1042 | (setcar n 1))) |
| 1039 | (while (eq (car-safe (setq n (car np))) '*) | 1043 | (while (eq (car-safe (setq n (car np))) '*) |
| 1040 | (math-simplify-units-divisor (cdr n) (cdr (cdr expr))) | 1044 | (math-simplify-units-divisor (cdr n) (cdr (cdr math-simplify-expr))) |
| 1041 | (setq np (cdr (cdr n)))) | 1045 | (setq np (cdr (cdr n)))) |
| 1042 | (math-simplify-units-divisor np (cdr (cdr expr))) | 1046 | (math-simplify-units-divisor np (cdr (cdr math-simplify-expr))) |
| 1043 | (if (eq try-cancel-units 0) | 1047 | (if (eq try-cancel-units 0) |
| 1044 | (let* ((math-simplifying-units nil) | 1048 | (let* ((math-simplifying-units nil) |
| 1045 | (base (math-simplify (math-to-standard-units expr nil)))) | 1049 | (base (math-simplify |
| 1050 | (math-to-standard-units math-simplify-expr nil)))) | ||
| 1046 | (if (Math-numberp base) | 1051 | (if (Math-numberp base) |
| 1047 | (setq expr base)))) | 1052 | (setq math-simplify-expr base)))) |
| 1048 | (if (eq (car-safe expr) '/) | 1053 | (if (eq (car-safe math-simplify-expr) '/) |
| 1049 | (math-simplify-units-prod)) | 1054 | (math-simplify-units-prod)) |
| 1050 | expr))) | 1055 | math-simplify-expr))) |
| 1051 | 1056 | ||
| 1052 | (defun math-simplify-units-divisor (np dp) | 1057 | (defun math-simplify-units-divisor (np dp) |
| 1053 | (let ((n (car np)) | 1058 | (let ((n (car np)) |
| @@ -1094,20 +1099,23 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 1094 | 1099 | ||
| 1095 | (math-defsimplify ^ | 1100 | (math-defsimplify ^ |
| 1096 | (and math-simplifying-units | 1101 | (and math-simplifying-units |
| 1097 | (math-realp (nth 2 expr)) | 1102 | (math-realp (nth 2 math-simplify-expr)) |
| 1098 | (if (memq (car-safe (nth 1 expr)) '(* /)) | 1103 | (if (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
| 1099 | (list (car (nth 1 expr)) | 1104 | (list (car (nth 1 math-simplify-expr)) |
| 1100 | (list '^ (nth 1 (nth 1 expr)) (nth 2 expr)) | 1105 | (list '^ (nth 1 (nth 1 math-simplify-expr)) |
| 1101 | (list '^ (nth 2 (nth 1 expr)) (nth 2 expr))) | 1106 | (nth 2 math-simplify-expr)) |
| 1102 | (math-simplify-units-pow (nth 1 expr) (nth 2 expr))))) | 1107 | (list '^ (nth 2 (nth 1 math-simplify-expr)) |
| 1108 | (nth 2 math-simplify-expr))) | ||
| 1109 | (math-simplify-units-pow (nth 1 math-simplify-expr) | ||
| 1110 | (nth 2 math-simplify-expr))))) | ||
| 1103 | 1111 | ||
| 1104 | (math-defsimplify calcFunc-sqrt | 1112 | (math-defsimplify calcFunc-sqrt |
| 1105 | (and math-simplifying-units | 1113 | (and math-simplifying-units |
| 1106 | (if (memq (car-safe (nth 1 expr)) '(* /)) | 1114 | (if (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
| 1107 | (list (car (nth 1 expr)) | 1115 | (list (car (nth 1 math-simplify-expr)) |
| 1108 | (list 'calcFunc-sqrt (nth 1 (nth 1 expr))) | 1116 | (list 'calcFunc-sqrt (nth 1 (nth 1 math-simplify-expr))) |
| 1109 | (list 'calcFunc-sqrt (nth 2 (nth 1 expr)))) | 1117 | (list 'calcFunc-sqrt (nth 2 (nth 1 math-simplify-expr)))) |
| 1110 | (math-simplify-units-pow (nth 1 expr) '(frac 1 2))))) | 1118 | (math-simplify-units-pow (nth 1 math-simplify-expr) '(frac 1 2))))) |
| 1111 | 1119 | ||
| 1112 | (math-defsimplify (calcFunc-floor | 1120 | (math-defsimplify (calcFunc-floor |
| 1113 | calcFunc-ceil | 1121 | calcFunc-ceil |
| @@ -1120,21 +1128,21 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 1120 | calcFunc-abs | 1128 | calcFunc-abs |
| 1121 | calcFunc-clean) | 1129 | calcFunc-clean) |
| 1122 | (and math-simplifying-units | 1130 | (and math-simplifying-units |
| 1123 | (= (length expr) 2) | 1131 | (= (length math-simplify-expr) 2) |
| 1124 | (if (math-only-units-in-expr-p (nth 1 expr)) | 1132 | (if (math-only-units-in-expr-p (nth 1 math-simplify-expr)) |
| 1125 | (nth 1 expr) | 1133 | (nth 1 math-simplify-expr) |
| 1126 | (if (and (memq (car-safe (nth 1 expr)) '(* /)) | 1134 | (if (and (memq (car-safe (nth 1 math-simplify-expr)) '(* /)) |
| 1127 | (or (math-only-units-in-expr-p | 1135 | (or (math-only-units-in-expr-p |
| 1128 | (nth 1 (nth 1 expr))) | 1136 | (nth 1 (nth 1 math-simplify-expr))) |
| 1129 | (math-only-units-in-expr-p | 1137 | (math-only-units-in-expr-p |
| 1130 | (nth 2 (nth 1 expr))))) | 1138 | (nth 2 (nth 1 math-simplify-expr))))) |
| 1131 | (list (car (nth 1 expr)) | 1139 | (list (car (nth 1 math-simplify-expr)) |
| 1132 | (cons (car expr) | 1140 | (cons (car math-simplify-expr) |
| 1133 | (cons (nth 1 (nth 1 expr)) | 1141 | (cons (nth 1 (nth 1 math-simplify-expr)) |
| 1134 | (cdr (cdr expr)))) | 1142 | (cdr (cdr math-simplify-expr)))) |
| 1135 | (cons (car expr) | 1143 | (cons (car math-simplify-expr) |
| 1136 | (cons (nth 2 (nth 1 expr)) | 1144 | (cons (nth 2 (nth 1 math-simplify-expr)) |
| 1137 | (cdr (cdr expr))))))))) | 1145 | (cdr (cdr math-simplify-expr))))))))) |
| 1138 | 1146 | ||
| 1139 | (defun math-simplify-units-pow (a pow) | 1147 | (defun math-simplify-units-pow (a pow) |
| 1140 | (if (and (eq (car-safe a) '^) | 1148 | (if (and (eq (car-safe a) '^) |
| @@ -1157,10 +1165,10 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 1157 | 1165 | ||
| 1158 | (math-defsimplify calcFunc-sin | 1166 | (math-defsimplify calcFunc-sin |
| 1159 | (and math-simplifying-units | 1167 | (and math-simplifying-units |
| 1160 | (math-units-in-expr-p (nth 1 expr) nil) | 1168 | (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
| 1161 | (let ((rad (math-simplify-units | 1169 | (let ((rad (math-simplify-units |
| 1162 | (math-evaluate-expr | 1170 | (math-evaluate-expr |
| 1163 | (math-to-standard-units (nth 1 expr) nil)))) | 1171 | (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
| 1164 | (calc-angle-mode 'rad)) | 1172 | (calc-angle-mode 'rad)) |
| 1165 | (and (eq (car-safe rad) '*) | 1173 | (and (eq (car-safe rad) '*) |
| 1166 | (math-realp (nth 1 rad)) | 1174 | (math-realp (nth 1 rad)) |
| @@ -1170,10 +1178,10 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 1170 | 1178 | ||
| 1171 | (math-defsimplify calcFunc-cos | 1179 | (math-defsimplify calcFunc-cos |
| 1172 | (and math-simplifying-units | 1180 | (and math-simplifying-units |
| 1173 | (math-units-in-expr-p (nth 1 expr) nil) | 1181 | (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
| 1174 | (let ((rad (math-simplify-units | 1182 | (let ((rad (math-simplify-units |
| 1175 | (math-evaluate-expr | 1183 | (math-evaluate-expr |
| 1176 | (math-to-standard-units (nth 1 expr) nil)))) | 1184 | (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
| 1177 | (calc-angle-mode 'rad)) | 1185 | (calc-angle-mode 'rad)) |
| 1178 | (and (eq (car-safe rad) '*) | 1186 | (and (eq (car-safe rad) '*) |
| 1179 | (math-realp (nth 1 rad)) | 1187 | (math-realp (nth 1 rad)) |
| @@ -1183,10 +1191,10 @@ Entries are (SYMBOL EXPR DOC-STRING TEMP-TYPE BASE-UNITS).") | |||
| 1183 | 1191 | ||
| 1184 | (math-defsimplify calcFunc-tan | 1192 | (math-defsimplify calcFunc-tan |
| 1185 | (and math-simplifying-units | 1193 | (and math-simplifying-units |
| 1186 | (math-units-in-expr-p (nth 1 expr) nil) | 1194 | (math-units-in-expr-p (nth 1 math-simplify-expr) nil) |
| 1187 | (let ((rad (math-simplify-units | 1195 | (let ((rad (math-simplify-units |
| 1188 | (math-evaluate-expr | 1196 | (math-evaluate-expr |
| 1189 | (math-to-standard-units (nth 1 expr) nil)))) | 1197 | (math-to-standard-units (nth 1 math-simplify-expr) nil)))) |
| 1190 | (calc-angle-mode 'rad)) | 1198 | (calc-angle-mode 'rad)) |
| 1191 | (and (eq (car-safe rad) '*) | 1199 | (and (eq (car-safe rad) '*) |
| 1192 | (math-realp (nth 1 rad)) | 1200 | (math-realp (nth 1 rad)) |