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