Fix typo in ChangeLog for last commit.
[emacs.git] / lisp / calc / calc-macs.el
blob4b75f8d4ae826e9bc8e65b853b06fc06fb0f2f2a
1 ;;; calc-macs.el --- important macros for Calc
3 ;; Copyright (C) 1990-1993, 2001-2013 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; Declare functions which are defined elsewhere.
28 (declare-function math-zerop "calc-misc" (a))
29 (declare-function math-negp "calc-misc" (a))
30 (declare-function math-looks-negp "calc-misc" (a))
31 (declare-function math-posp "calc-misc" (a))
32 (declare-function math-compare "calc-ext" (a b))
33 (declare-function math-bignum "calc" (a))
34 (declare-function math-compare-bignum "calc-ext" (a b))
37 (defmacro calc-wrapper (&rest body)
38 `(calc-do (function (lambda ()
39 ,@body))))
41 (defmacro calc-slow-wrapper (&rest body)
42 `(calc-do
43 (function (lambda () ,@body)) (point)))
45 (defmacro math-showing-full-precision (form)
46 `(let ((calc-float-format calc-full-float-format))
47 ,form))
49 (defmacro math-with-extra-prec (delta &rest body)
50 `(math-normalize
51 (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
52 ,@body)))
54 (defmacro math-working (msg arg) ; [Public]
55 `(if (eq calc-display-working-message 'lots)
56 (math-do-working ,msg ,arg)))
58 (defmacro calc-with-default-simplification (&rest body)
59 `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
60 calc-simplify-mode)))
61 ,@body))
63 (defmacro calc-with-trail-buffer (&rest body)
64 `(let ((save-buf (current-buffer))
65 (calc-command-flags nil))
66 (with-current-buffer (calc-trail-display t)
67 (progn
68 (goto-char calc-trail-pointer)
69 ,@body))))
71 ;;; Faster in-line version zerop, normalized values only.
72 (defsubst Math-zerop (a) ; [P N]
73 (if (consp a)
74 (and (not (memq (car a) '(bigpos bigneg)))
75 (if (eq (car a) 'float)
76 (eq (nth 1 a) 0)
77 (math-zerop a)))
78 (eq a 0)))
80 (defsubst Math-integer-negp (a)
81 (if (consp a)
82 (eq (car a) 'bigneg)
83 (< a 0)))
85 (defsubst Math-integer-posp (a)
86 (if (consp a)
87 (eq (car a) 'bigpos)
88 (> a 0)))
90 (defsubst Math-negp (a)
91 (if (consp a)
92 (or (eq (car a) 'bigneg)
93 (and (not (eq (car a) 'bigpos))
94 (if (memq (car a) '(frac float))
95 (Math-integer-negp (nth 1 a))
96 (math-negp a))))
97 (< a 0)))
99 (defsubst Math-looks-negp (a) ; [P x] [Public]
100 (or (Math-negp a)
101 (and (consp a) (or (eq (car a) 'neg)
102 (and (memq (car a) '(* /))
103 (or (math-looks-negp (nth 1 a))
104 (math-looks-negp (nth 2 a))))))))
106 (defsubst Math-posp (a)
107 (if (consp a)
108 (or (eq (car a) 'bigpos)
109 (and (not (eq (car a) 'bigneg))
110 (if (memq (car a) '(frac float))
111 (Math-integer-posp (nth 1 a))
112 (math-posp a))))
113 (> a 0)))
115 (defsubst Math-integerp (a)
116 (or (not (consp a))
117 (memq (car a) '(bigpos bigneg))))
119 (defsubst Math-natnump (a)
120 (if (consp a)
121 (eq (car a) 'bigpos)
122 (>= a 0)))
124 (defsubst Math-ratp (a)
125 (or (not (consp a))
126 (memq (car a) '(bigpos bigneg frac))))
128 (defsubst Math-realp (a)
129 (or (not (consp a))
130 (memq (car a) '(bigpos bigneg frac float))))
132 (defsubst Math-anglep (a)
133 (or (not (consp a))
134 (memq (car a) '(bigpos bigneg frac float hms))))
136 (defsubst Math-numberp (a)
137 (or (not (consp a))
138 (memq (car a) '(bigpos bigneg frac float cplx polar))))
140 (defsubst Math-scalarp (a)
141 (or (not (consp a))
142 (memq (car a) '(bigpos bigneg frac float cplx polar hms))))
144 (defsubst Math-vectorp (a)
145 (and (consp a) (eq (car a) 'vec)))
147 (defsubst Math-messy-integerp (a)
148 (and (consp a)
149 (eq (car a) 'float)
150 (>= (nth 2 a) 0)))
152 (defsubst Math-objectp (a) ; [Public]
153 (or (not (consp a))
154 (memq (car a)
155 '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
157 (defsubst Math-objvecp (a) ; [Public]
158 (or (not (consp a))
159 (memq (car a)
160 '(bigpos bigneg frac float cplx polar hms date
161 sdev intv mod vec))))
163 ;;; Compute the negative of A. [O O; o o] [Public]
164 (defsubst Math-integer-neg (a)
165 (if (consp a)
166 (if (eq (car a) 'bigpos)
167 (cons 'bigneg (cdr a))
168 (cons 'bigpos (cdr a)))
169 (- a)))
171 (defsubst Math-equal (a b)
172 (= (math-compare a b) 0))
174 (defsubst Math-lessp (a b)
175 (= (math-compare a b) -1))
177 (defsubst Math-primp (a)
178 (or (not (consp a))
179 (memq (car a) '(bigpos bigneg frac float cplx polar
180 hms date mod var))))
182 (defsubst Math-num-integerp (a)
183 (or (not (consp a))
184 (memq (car a) '(bigpos bigneg))
185 (and (eq (car a) 'float)
186 (>= (nth 2 a) 0))))
188 (defsubst Math-bignum-test (a) ; [B N; B s; b b]
189 (if (consp a)
191 (math-bignum a)))
193 (defsubst Math-equal-int (a b)
194 (or (eq a b)
195 (and (consp a)
196 (eq (car a) 'float)
197 (eq (nth 1 a) b)
198 (= (nth 2 a) 0))))
200 (defsubst Math-natnum-lessp (a b)
201 (if (consp a)
202 (and (consp b)
203 (= (math-compare-bignum (cdr a) (cdr b)) -1))
204 (or (consp b)
205 (< a b))))
207 (provide 'calc-macs)
209 ;;; calc-macs.el ends here