Fix EOL mishap.
[emacs.git] / lisp / calc / calc-macs.el
blobda82c9632a40c2758f3d90430a397f6629fc3b76
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/>.
24 ;;; Commentary:
26 ;;; Code:
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 ()
40 ,@body))))
42 (defmacro calc-slow-wrapper (&rest body)
43 `(calc-do
44 (function (lambda () ,@body)) (point)))
46 (defmacro math-showing-full-precision (form)
47 `(let ((calc-float-format calc-full-float-format))
48 ,form))
50 (defmacro math-with-extra-prec (delta &rest body)
51 `(math-normalize
52 (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
53 ,@body)))
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)))
61 calc-simplify-mode)))
62 ,@body))
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)
68 (progn
69 (goto-char calc-trail-pointer)
70 ,@body))))
72 ;;; Faster in-line version zerop, normalized values only.
73 (defsubst Math-zerop (a) ; [P N]
74 (if (consp a)
75 (and (not (memq (car a) '(bigpos bigneg)))
76 (if (eq (car a) 'float)
77 (eq (nth 1 a) 0)
78 (math-zerop a)))
79 (eq a 0)))
81 (defsubst Math-integer-negp (a)
82 (if (consp a)
83 (eq (car a) 'bigneg)
84 (< a 0)))
86 (defsubst Math-integer-posp (a)
87 (if (consp a)
88 (eq (car a) 'bigpos)
89 (> a 0)))
91 (defsubst Math-negp (a)
92 (if (consp 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))
97 (math-negp a))))
98 (< a 0)))
100 (defsubst Math-looks-negp (a) ; [P x] [Public]
101 (or (Math-negp a)
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)
108 (if (consp 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))
113 (math-posp a))))
114 (> a 0)))
116 (defsubst Math-integerp (a)
117 (or (not (consp a))
118 (memq (car a) '(bigpos bigneg))))
120 (defsubst Math-natnump (a)
121 (if (consp a)
122 (eq (car a) 'bigpos)
123 (>= a 0)))
125 (defsubst Math-ratp (a)
126 (or (not (consp a))
127 (memq (car a) '(bigpos bigneg frac))))
129 (defsubst Math-realp (a)
130 (or (not (consp a))
131 (memq (car a) '(bigpos bigneg frac float))))
133 (defsubst Math-anglep (a)
134 (or (not (consp a))
135 (memq (car a) '(bigpos bigneg frac float hms))))
137 (defsubst Math-numberp (a)
138 (or (not (consp a))
139 (memq (car a) '(bigpos bigneg frac float cplx polar))))
141 (defsubst Math-scalarp (a)
142 (or (not (consp 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)
149 (and (consp a)
150 (eq (car a) 'float)
151 (>= (nth 2 a) 0)))
153 (defsubst Math-objectp (a) ; [Public]
154 (or (not (consp a))
155 (memq (car a)
156 '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
158 (defsubst Math-objvecp (a) ; [Public]
159 (or (not (consp a))
160 (memq (car a)
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)
166 (if (consp a)
167 (if (eq (car a) 'bigpos)
168 (cons 'bigneg (cdr a))
169 (cons 'bigpos (cdr a)))
170 (- 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)
179 (or (not (consp a))
180 (memq (car a) '(bigpos bigneg frac float cplx polar
181 hms date mod var))))
183 (defsubst Math-num-integerp (a)
184 (or (not (consp a))
185 (memq (car a) '(bigpos bigneg))
186 (and (eq (car a) 'float)
187 (>= (nth 2 a) 0))))
189 (defsubst Math-bignum-test (a) ; [B N; B s; b b]
190 (if (consp a)
192 (math-bignum a)))
194 (defsubst Math-equal-int (a b)
195 (or (eq a b)
196 (and (consp a)
197 (eq (car a) 'float)
198 (eq (nth 1 a) b)
199 (= (nth 2 a) 0))))
201 (defsubst Math-natnum-lessp (a b)
202 (if (consp a)
203 (and (consp b)
204 (= (math-compare-bignum (cdr a) (cdr b)) -1))
205 (or (consp b)
206 (< a b))))
208 (provide 'calc-macs)
210 ;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
211 ;;; calc-macs.el ends here