(while-no-input): Don't splice BODY directly into the `or' form.
[emacs.git] / lisp / calc / calc-macs.el
blobc5d06031de7a90198764eb08159e236f0aa91b22
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, or (at your option)
14 ;; 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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;;; Code:
30 ;; Declare functions which are defined elsewhere.
31 (declare-function math-zerop "calc-misc" (a))
32 (declare-function math-negp "calc-misc" (a))
33 (declare-function math-looks-negp "calc-misc" (a))
34 (declare-function math-posp "calc-misc" (a))
35 (declare-function math-compare "calc-ext" (a b))
36 (declare-function math-bignum "calc" (a))
37 (declare-function math-compare-bignum "calc-ext" (a b))
40 (defmacro calc-wrapper (&rest body)
41 `(calc-do (function (lambda ()
42 ,@body))))
44 (defmacro calc-slow-wrapper (&rest body)
45 `(calc-do
46 (function (lambda () ,@body)) (point)))
48 (defmacro math-showing-full-precision (form)
49 `(let ((calc-float-format calc-full-float-format))
50 ,form))
52 (defmacro math-with-extra-prec (delta &rest body)
53 `(math-normalize
54 (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
55 ,@body)))
57 (defmacro math-working (msg arg) ; [Public]
58 `(if (eq calc-display-working-message 'lots)
59 (math-do-working ,msg ,arg)))
61 (defmacro calc-with-default-simplification (&rest body)
62 `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
63 calc-simplify-mode)))
64 ,@body))
66 (defmacro calc-with-trail-buffer (&rest body)
67 `(let ((save-buf (current-buffer))
68 (calc-command-flags nil))
69 (with-current-buffer (calc-trail-display t)
70 (progn
71 (goto-char calc-trail-pointer)
72 ,@body))))
74 ;;; Faster in-line version zerop, normalized values only.
75 (defsubst Math-zerop (a) ; [P N]
76 (if (consp a)
77 (and (not (memq (car a) '(bigpos bigneg)))
78 (if (eq (car a) 'float)
79 (eq (nth 1 a) 0)
80 (math-zerop a)))
81 (eq a 0)))
83 (defsubst Math-integer-negp (a)
84 (if (consp a)
85 (eq (car a) 'bigneg)
86 (< a 0)))
88 (defsubst Math-integer-posp (a)
89 (if (consp a)
90 (eq (car a) 'bigpos)
91 (> a 0)))
93 (defsubst Math-negp (a)
94 (if (consp a)
95 (or (eq (car a) 'bigneg)
96 (and (not (eq (car a) 'bigpos))
97 (if (memq (car a) '(frac float))
98 (Math-integer-negp (nth 1 a))
99 (math-negp a))))
100 (< a 0)))
102 (defsubst Math-looks-negp (a) ; [P x] [Public]
103 (or (Math-negp a)
104 (and (consp a) (or (eq (car a) 'neg)
105 (and (memq (car a) '(* /))
106 (or (math-looks-negp (nth 1 a))
107 (math-looks-negp (nth 2 a))))))))
109 (defsubst Math-posp (a)
110 (if (consp a)
111 (or (eq (car a) 'bigpos)
112 (and (not (eq (car a) 'bigneg))
113 (if (memq (car a) '(frac float))
114 (Math-integer-posp (nth 1 a))
115 (math-posp a))))
116 (> a 0)))
118 (defsubst Math-integerp (a)
119 (or (not (consp a))
120 (memq (car a) '(bigpos bigneg))))
122 (defsubst Math-natnump (a)
123 (if (consp a)
124 (eq (car a) 'bigpos)
125 (>= a 0)))
127 (defsubst Math-ratp (a)
128 (or (not (consp a))
129 (memq (car a) '(bigpos bigneg frac))))
131 (defsubst Math-realp (a)
132 (or (not (consp a))
133 (memq (car a) '(bigpos bigneg frac float))))
135 (defsubst Math-anglep (a)
136 (or (not (consp a))
137 (memq (car a) '(bigpos bigneg frac float hms))))
139 (defsubst Math-numberp (a)
140 (or (not (consp a))
141 (memq (car a) '(bigpos bigneg frac float cplx polar))))
143 (defsubst Math-scalarp (a)
144 (or (not (consp a))
145 (memq (car a) '(bigpos bigneg frac float cplx polar hms))))
147 (defsubst Math-vectorp (a)
148 (and (consp a) (eq (car a) 'vec)))
150 (defsubst Math-messy-integerp (a)
151 (and (consp a)
152 (eq (car a) 'float)
153 (>= (nth 2 a) 0)))
155 (defsubst Math-objectp (a) ; [Public]
156 (or (not (consp a))
157 (memq (car a)
158 '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
160 (defsubst Math-objvecp (a) ; [Public]
161 (or (not (consp a))
162 (memq (car a)
163 '(bigpos bigneg frac float cplx polar hms date
164 sdev intv mod vec))))
166 ;;; Compute the negative of A. [O O; o o] [Public]
167 (defsubst Math-integer-neg (a)
168 (if (consp a)
169 (if (eq (car a) 'bigpos)
170 (cons 'bigneg (cdr a))
171 (cons 'bigpos (cdr a)))
172 (- a)))
174 (defsubst Math-equal (a b)
175 (= (math-compare a b) 0))
177 (defsubst Math-lessp (a b)
178 (= (math-compare a b) -1))
180 (defsubst Math-primp (a)
181 (or (not (consp a))
182 (memq (car a) '(bigpos bigneg frac float cplx polar
183 hms date mod var))))
185 (defsubst Math-num-integerp (a)
186 (or (not (consp a))
187 (memq (car a) '(bigpos bigneg))
188 (and (eq (car a) 'float)
189 (>= (nth 2 a) 0))))
191 (defsubst Math-bignum-test (a) ; [B N; B s; b b]
192 (if (consp a)
194 (math-bignum a)))
196 (defsubst Math-equal-int (a b)
197 (or (eq a b)
198 (and (consp a)
199 (eq (car a) 'float)
200 (eq (nth 1 a) b)
201 (= (nth 2 a) 0))))
203 (defsubst Math-natnum-lessp (a b)
204 (if (consp a)
205 (and (consp b)
206 (= (math-compare-bignum (cdr a) (cdr b)) -1))
207 (or (consp b)
208 (< a b))))
210 (provide 'calc-macs)
212 ;;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
213 ;;; calc-macs.el ends here