Commit | Line | Data |
---|---|---|
3e3b3c7e CW |
1 | ;;; calc-macs.el --- important macros for Calc |
2 | ||
bf77c646 | 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
3e3b3c7e CW |
4 | |
5 | ;; Author: David Gillespie <daveg@synaptics.com> | |
f50dfd02 | 6 | ;; Maintainer: Jay Belanger <belanger@truman.edu> |
136211a9 EZ |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
10 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 | ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 | ;; accepts responsibility to anyone for the consequences of using it | |
13 | ;; or for whether it serves any particular purpose or works at all, | |
14 | ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 | ;; License for full details. | |
16 | ||
17 | ;; Everyone is granted permission to copy, modify and redistribute | |
18 | ;; GNU Emacs, but only under the conditions described in the | |
19 | ;; GNU Emacs General Public License. A copy of this license is | |
20 | ;; supposed to have been given to you along with GNU Emacs so you | |
21 | ;; can know your rights and responsibilities. It should be in a | |
22 | ;; file named COPYING. Among other things, the copyright notice | |
23 | ;; and this notice must be preserved on all copies. | |
24 | ||
3e3b3c7e CW |
25 | ;;; Commentary: |
26 | ||
27 | ;;; Code: | |
136211a9 | 28 | |
136211a9 | 29 | (defmacro calc-wrapper (&rest body) |
3e3b3c7e CW |
30 | `(calc-do (function (lambda () |
31 | ,@body)))) | |
136211a9 | 32 | |
136211a9 | 33 | (defmacro calc-slow-wrapper (&rest body) |
3e3b3c7e | 34 | `(calc-do |
e7905671 | 35 | (function (lambda () ,@body)) (point))) |
136211a9 | 36 | |
3e3b3c7e CW |
37 | (defmacro math-showing-full-precision (form) |
38 | `(let ((calc-float-format calc-full-float-format)) | |
39 | ,form)) | |
136211a9 EZ |
40 | |
41 | (defmacro math-with-extra-prec (delta &rest body) | |
3e3b3c7e CW |
42 | `(math-normalize |
43 | (let ((calc-internal-prec (+ calc-internal-prec ,delta))) | |
44 | ,@body))) | |
136211a9 | 45 | |
3e3b3c7e CW |
46 | (defmacro math-working (msg arg) ; [Public] |
47 | `(if (eq calc-display-working-message 'lots) | |
48 | (math-do-working ,msg ,arg))) | |
136211a9 | 49 | |
061b2cc1 | 50 | (defmacro calc-with-default-simplification (&rest body) |
3e3b3c7e CW |
51 | `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num))) |
52 | calc-simplify-mode))) | |
53 | ,@body)) | |
136211a9 | 54 | |
3e3b3c7e CW |
55 | (defmacro calc-with-trail-buffer (&rest body) |
56 | `(let ((save-buf (current-buffer)) | |
57 | (calc-command-flags nil)) | |
58 | (with-current-buffer (calc-trail-display t) | |
59 | (progn | |
60 | (goto-char calc-trail-pointer) | |
61 | ,@body)))) | |
136211a9 | 62 | |
3e3b3c7e CW |
63 | ;;; Faster in-line version zerop, normalized values only. |
64 | (defsubst Math-zerop (a) ; [P N] | |
65 | (if (consp a) | |
66 | (and (not (memq (car a) '(bigpos bigneg))) | |
67 | (if (eq (car a) 'float) | |
68 | (eq (nth 1 a) 0) | |
69 | (math-zerop a))) | |
70 | (eq a 0))) | |
71 | ||
72 | (defsubst Math-integer-negp (a) | |
73 | (if (consp a) | |
74 | (eq (car a) 'bigneg) | |
75 | (< a 0))) | |
76 | ||
77 | (defsubst Math-integer-posp (a) | |
78 | (if (consp a) | |
79 | (eq (car a) 'bigpos) | |
80 | (> a 0))) | |
81 | ||
82 | (defsubst Math-negp (a) | |
83 | (if (consp a) | |
84 | (or (eq (car a) 'bigneg) | |
85 | (and (not (eq (car a) 'bigpos)) | |
86 | (if (memq (car a) '(frac float)) | |
87 | (Math-integer-negp (nth 1 a)) | |
88 | (math-negp a)))) | |
89 | (< a 0))) | |
90 | ||
91 | (defsubst Math-looks-negp (a) ; [P x] [Public] | |
92 | (or (Math-negp a) | |
93 | (and (consp a) (or (eq (car a) 'neg) | |
94 | (and (memq (car a) '(* /)) | |
95 | (or (math-looks-negp (nth 1 a)) | |
96 | (math-looks-negp (nth 2 a)))))))) | |
97 | ||
98 | (defsubst Math-posp (a) | |
99 | (if (consp a) | |
100 | (or (eq (car a) 'bigpos) | |
101 | (and (not (eq (car a) 'bigneg)) | |
102 | (if (memq (car a) '(frac float)) | |
103 | (Math-integer-posp (nth 1 a)) | |
104 | (math-posp a)))) | |
105 | (> a 0))) | |
106 | ||
107 | (defsubst Math-integerp (a) | |
108 | (or (not (consp a)) | |
109 | (memq (car a) '(bigpos bigneg)))) | |
110 | ||
111 | (defsubst Math-natnump (a) | |
112 | (if (consp a) | |
113 | (eq (car a) 'bigpos) | |
114 | (>= a 0))) | |
115 | ||
116 | (defsubst Math-ratp (a) | |
117 | (or (not (consp a)) | |
118 | (memq (car a) '(bigpos bigneg frac)))) | |
119 | ||
120 | (defsubst Math-realp (a) | |
121 | (or (not (consp a)) | |
122 | (memq (car a) '(bigpos bigneg frac float)))) | |
123 | ||
124 | (defsubst Math-anglep (a) | |
125 | (or (not (consp a)) | |
126 | (memq (car a) '(bigpos bigneg frac float hms)))) | |
127 | ||
128 | (defsubst Math-numberp (a) | |
129 | (or (not (consp a)) | |
130 | (memq (car a) '(bigpos bigneg frac float cplx polar)))) | |
131 | ||
132 | (defsubst Math-scalarp (a) | |
133 | (or (not (consp a)) | |
134 | (memq (car a) '(bigpos bigneg frac float cplx polar hms)))) | |
135 | ||
136 | (defsubst Math-vectorp (a) | |
137 | (and (consp a) (eq (car a) 'vec))) | |
138 | ||
139 | (defsubst Math-messy-integerp (a) | |
140 | (and (consp a) | |
141 | (eq (car a) 'float) | |
142 | (>= (nth 2 a) 0))) | |
143 | ||
144 | (defsubst Math-objectp (a) ; [Public] | |
145 | (or (not (consp a)) | |
146 | (memq (car a) | |
147 | '(bigpos bigneg frac float cplx polar hms date sdev intv mod)))) | |
148 | ||
149 | (defsubst Math-objvecp (a) ; [Public] | |
150 | (or (not (consp a)) | |
151 | (memq (car a) | |
152 | '(bigpos bigneg frac float cplx polar hms date | |
153 | sdev intv mod vec)))) | |
136211a9 | 154 | |
3e3b3c7e CW |
155 | ;;; Compute the negative of A. [O O; o o] [Public] |
156 | (defsubst Math-integer-neg (a) | |
157 | (if (consp a) | |
158 | (if (eq (car a) 'bigpos) | |
159 | (cons 'bigneg (cdr a)) | |
160 | (cons 'bigpos (cdr a))) | |
161 | (- a))) | |
162 | ||
163 | (defsubst Math-equal (a b) | |
164 | (= (math-compare a b) 0)) | |
165 | ||
166 | (defsubst Math-lessp (a b) | |
167 | (= (math-compare a b) -1)) | |
168 | ||
169 | (defsubst Math-primp (a) | |
170 | (or (not (consp a)) | |
171 | (memq (car a) '(bigpos bigneg frac float cplx polar | |
172 | hms date mod var)))) | |
173 | ||
174 | (defsubst Math-num-integerp (a) | |
175 | (or (not (consp a)) | |
176 | (memq (car a) '(bigpos bigneg)) | |
177 | (and (eq (car a) 'float) | |
178 | (>= (nth 2 a) 0)))) | |
179 | ||
180 | (defsubst Math-bignum-test (a) ; [B N; B s; b b] | |
181 | (if (consp a) | |
182 | a | |
183 | (math-bignum a))) | |
184 | ||
185 | (defsubst Math-equal-int (a b) | |
186 | (or (eq a b) | |
187 | (and (consp a) | |
188 | (eq (car a) 'float) | |
189 | (eq (nth 1 a) b) | |
190 | (= (nth 2 a) 0)))) | |
191 | ||
192 | (defsubst Math-natnum-lessp (a b) | |
193 | (if (consp a) | |
194 | (and (consp b) | |
195 | (= (math-compare-bignum (cdr a) (cdr b)) -1)) | |
196 | (or (consp b) | |
197 | (< a b)))) | |
136211a9 | 198 | |
f50dfd02 JB |
199 | (provide 'calc-macs) |
200 | ||
ab5796a9 | 201 | ;;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e |
bf77c646 | 202 | ;;; calc-macs.el ends here |