1 ;;; calc-macs.el --- important macros for Calc
3 ;; Copyright (C) 1990-1993, 2001-2017 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ;; Declare functions which are defined elsewhere.
27 (declare-function math-zerop
"calc-misc" (a))
28 (declare-function math-negp
"calc-misc" (a))
29 (declare-function math-looks-negp
"calc-misc" (a))
30 (declare-function math-posp
"calc-misc" (a))
31 (declare-function math-compare
"calc-ext" (a b
))
32 (declare-function math-bignum
"calc" (a))
33 (declare-function math-compare-bignum
"calc-ext" (a b
))
36 (defmacro calc-wrapper
(&rest body
)
37 `(calc-do (function (lambda ()
40 (defmacro calc-slow-wrapper
(&rest body
)
42 (function (lambda () ,@body
)) (point)))
44 (defmacro math-showing-full-precision
(form)
45 `(let ((calc-float-format calc-full-float-format
))
48 (defmacro math-with-extra-prec
(delta &rest body
)
50 (let ((calc-internal-prec (+ calc-internal-prec
,delta
)))
53 (defmacro math-working
(msg arg
) ; [Public]
54 `(if (eq calc-display-working-message
'lots
)
55 (math-do-working ,msg
,arg
)))
57 (defmacro calc-with-default-simplification
(&rest body
)
58 `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode
'(none num
)))
62 (defmacro calc-with-trail-buffer
(&rest body
)
63 `(let ((save-buf (current-buffer))
64 (calc-command-flags nil
))
65 (with-current-buffer (calc-trail-display t
)
67 (goto-char calc-trail-pointer
)
70 ;;; Faster in-line version zerop, normalized values only.
71 (defsubst Math-zerop
(a) ; [P N]
73 (and (not (memq (car a
) '(bigpos bigneg
)))
74 (if (eq (car a
) 'float
)
79 (defsubst Math-integer-negp
(a)
84 (defsubst Math-integer-posp
(a)
89 (defsubst Math-negp
(a)
91 (or (eq (car a
) 'bigneg
)
92 (and (not (eq (car a
) 'bigpos
))
93 (if (memq (car a
) '(frac float
))
94 (Math-integer-negp (nth 1 a
))
98 (defsubst Math-looks-negp
(a) ; [P x] [Public]
100 (and (consp a
) (or (eq (car a
) 'neg
)
101 (and (memq (car a
) '(* /))
102 (or (math-looks-negp (nth 1 a
))
103 (math-looks-negp (nth 2 a
))))))))
105 (defsubst Math-posp
(a)
107 (or (eq (car a
) 'bigpos
)
108 (and (not (eq (car a
) 'bigneg
))
109 (if (memq (car a
) '(frac float
))
110 (Math-integer-posp (nth 1 a
))
114 (defsubst Math-integerp
(a)
116 (memq (car a
) '(bigpos bigneg
))))
118 (defsubst Math-natnump
(a)
123 (defsubst Math-ratp
(a)
125 (memq (car a
) '(bigpos bigneg frac
))))
127 (defsubst Math-realp
(a)
129 (memq (car a
) '(bigpos bigneg frac float
))))
131 (defsubst Math-anglep
(a)
133 (memq (car a
) '(bigpos bigneg frac float hms
))))
135 (defsubst Math-numberp
(a)
137 (memq (car a
) '(bigpos bigneg frac float cplx polar
))))
139 (defsubst Math-scalarp
(a)
141 (memq (car a
) '(bigpos bigneg frac float cplx polar hms
))))
143 (defsubst Math-vectorp
(a)
144 (and (consp a
) (eq (car a
) 'vec
)))
146 (defsubst Math-messy-integerp
(a)
151 (defsubst Math-objectp
(a) ; [Public]
154 '(bigpos bigneg frac float cplx polar hms date sdev intv mod
))))
156 (defsubst Math-objvecp
(a) ; [Public]
159 '(bigpos bigneg frac float cplx polar hms date
160 sdev intv mod vec
))))
162 ;;; Compute the negative of A. [O O; o o] [Public]
163 (defsubst Math-integer-neg
(a)
165 (if (eq (car a
) 'bigpos
)
166 (cons 'bigneg
(cdr a
))
167 (cons 'bigpos
(cdr a
)))
170 (defsubst Math-equal
(a b
)
171 (= (math-compare a b
) 0))
173 (defsubst Math-lessp
(a b
)
174 (= (math-compare a b
) -
1))
176 (defsubst Math-primp
(a)
178 (memq (car a
) '(bigpos bigneg frac float cplx polar
181 (defsubst Math-num-integerp
(a)
183 (memq (car a
) '(bigpos bigneg
))
184 (and (eq (car a
) 'float
)
187 (defsubst Math-bignum-test
(a) ; [B N; B s; b b]
192 (defsubst Math-equal-int
(a b
)
199 (defsubst Math-natnum-lessp
(a b
)
202 (= (math-compare-bignum (cdr a
) (cdr b
)) -
1))
208 ;;; calc-macs.el ends here