1 ;;; calc-macs.el --- important macros for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; Declare functions which are defined elsewhere.
29 (declare-function math-zerop
"calc-misc" (a))
30 (declare-function math-negp
"calc-misc" (a))
31 (declare-function math-looks-negp
"calc-misc" (a))
32 (declare-function math-posp
"calc-misc" (a))
33 (declare-function math-compare
"calc-ext" (a b
))
34 (declare-function math-bignum
"calc" (a))
35 (declare-function math-compare-bignum
"calc-ext" (a b
))
38 (defmacro calc-wrapper
(&rest body
)
39 `(calc-do (function (lambda ()
42 (defmacro calc-slow-wrapper
(&rest body
)
44 (function (lambda () ,@body
)) (point)))
46 (defmacro math-showing-full-precision
(form)
47 `(let ((calc-float-format calc-full-float-format
))
50 (defmacro math-with-extra-prec
(delta &rest body
)
52 (let ((calc-internal-prec (+ calc-internal-prec
,delta
)))
55 (defmacro math-working
(msg arg
) ; [Public]
56 `(if (eq calc-display-working-message
'lots
)
57 (math-do-working ,msg
,arg
)))
59 (defmacro calc-with-default-simplification
(&rest body
)
60 `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode
'(none num
)))
64 (defmacro calc-with-trail-buffer
(&rest body
)
65 `(let ((save-buf (current-buffer))
66 (calc-command-flags nil
))
67 (with-current-buffer (calc-trail-display t
)
69 (goto-char calc-trail-pointer
)
72 ;;; Faster in-line version zerop, normalized values only.
73 (defsubst Math-zerop
(a) ; [P N]
75 (and (not (memq (car a
) '(bigpos bigneg
)))
76 (if (eq (car a
) 'float
)
81 (defsubst Math-integer-negp
(a)
86 (defsubst Math-integer-posp
(a)
91 (defsubst Math-negp
(a)
93 (or (eq (car a
) 'bigneg
)
94 (and (not (eq (car a
) 'bigpos
))
95 (if (memq (car a
) '(frac float
))
96 (Math-integer-negp (nth 1 a
))
100 (defsubst Math-looks-negp
(a) ; [P x] [Public]
102 (and (consp a
) (or (eq (car a
) 'neg
)
103 (and (memq (car a
) '(* /))
104 (or (math-looks-negp (nth 1 a
))
105 (math-looks-negp (nth 2 a
))))))))
107 (defsubst Math-posp
(a)
109 (or (eq (car a
) 'bigpos
)
110 (and (not (eq (car a
) 'bigneg
))
111 (if (memq (car a
) '(frac float
))
112 (Math-integer-posp (nth 1 a
))
116 (defsubst Math-integerp
(a)
118 (memq (car a
) '(bigpos bigneg
))))
120 (defsubst Math-natnump
(a)
125 (defsubst Math-ratp
(a)
127 (memq (car a
) '(bigpos bigneg frac
))))
129 (defsubst Math-realp
(a)
131 (memq (car a
) '(bigpos bigneg frac float
))))
133 (defsubst Math-anglep
(a)
135 (memq (car a
) '(bigpos bigneg frac float hms
))))
137 (defsubst Math-numberp
(a)
139 (memq (car a
) '(bigpos bigneg frac float cplx polar
))))
141 (defsubst Math-scalarp
(a)
143 (memq (car a
) '(bigpos bigneg frac float cplx polar hms
))))
145 (defsubst Math-vectorp
(a)
146 (and (consp a
) (eq (car a
) 'vec
)))
148 (defsubst Math-messy-integerp
(a)
153 (defsubst Math-objectp
(a) ; [Public]
156 '(bigpos bigneg frac float cplx polar hms date sdev intv mod
))))
158 (defsubst Math-objvecp
(a) ; [Public]
161 '(bigpos bigneg frac float cplx polar hms date
162 sdev intv mod vec
))))
164 ;;; Compute the negative of A. [O O; o o] [Public]
165 (defsubst Math-integer-neg
(a)
167 (if (eq (car a
) 'bigpos
)
168 (cons 'bigneg
(cdr a
))
169 (cons 'bigpos
(cdr a
)))
172 (defsubst Math-equal
(a b
)
173 (= (math-compare a b
) 0))
175 (defsubst Math-lessp
(a b
)
176 (= (math-compare a b
) -
1))
178 (defsubst Math-primp
(a)
180 (memq (car a
) '(bigpos bigneg frac float cplx polar
183 (defsubst Math-num-integerp
(a)
185 (memq (car a
) '(bigpos bigneg
))
186 (and (eq (car a
) 'float
)
189 (defsubst Math-bignum-test
(a) ; [B N; B s; b b]
194 (defsubst Math-equal-int
(a b
)
201 (defsubst Math-natnum-lessp
(a b
)
204 (= (math-compare-bignum (cdr a
) (cdr b
)) -
1))
210 ;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
211 ;;; calc-macs.el ends here