Commit | Line | Data |
---|---|---|
3e3b3c7e CW |
1 | ;;; calc-macs.el --- important macros for Calc |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 1990-1993, 2001-2013 Free Software Foundation, Inc. |
3e3b3c7e CW |
4 | |
5 | ;; Author: David Gillespie <daveg@synaptics.com> | |
e8fff8ed | 6 | ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> |
136211a9 EZ |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
662c9c64 | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
7c671b23 | 11 | ;; it under the terms of the GNU General Public License as published by |
662c9c64 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
7c671b23 | 14 | |
136211a9 | 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
7c671b23 GM |
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. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
662c9c64 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
136211a9 | 22 | |
3e3b3c7e CW |
23 | ;;; Commentary: |
24 | ||
25 | ;;; Code: | |
136211a9 | 26 | |
84309b3b JB |
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)) | |
35 | ||
36 | ||
136211a9 | 37 | (defmacro calc-wrapper (&rest body) |
3e3b3c7e CW |
38 | `(calc-do (function (lambda () |
39 | ,@body)))) | |
136211a9 | 40 | |
136211a9 | 41 | (defmacro calc-slow-wrapper (&rest body) |
3e3b3c7e | 42 | `(calc-do |
e7905671 | 43 | (function (lambda () ,@body)) (point))) |
136211a9 | 44 | |
3e3b3c7e CW |
45 | (defmacro math-showing-full-precision (form) |
46 | `(let ((calc-float-format calc-full-float-format)) | |
47 | ,form)) | |
136211a9 EZ |
48 | |
49 | (defmacro math-with-extra-prec (delta &rest body) | |
3e3b3c7e CW |
50 | `(math-normalize |
51 | (let ((calc-internal-prec (+ calc-internal-prec ,delta))) | |
52 | ,@body))) | |
136211a9 | 53 | |
3e3b3c7e CW |
54 | (defmacro math-working (msg arg) ; [Public] |
55 | `(if (eq calc-display-working-message 'lots) | |
56 | (math-do-working ,msg ,arg))) | |
136211a9 | 57 | |
061b2cc1 | 58 | (defmacro calc-with-default-simplification (&rest body) |
3e3b3c7e CW |
59 | `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num))) |
60 | calc-simplify-mode))) | |
61 | ,@body)) | |
136211a9 | 62 | |
3e3b3c7e CW |
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)))) | |
136211a9 | 70 | |
3e3b3c7e CW |
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))) | |
79 | ||
80 | (defsubst Math-integer-negp (a) | |
81 | (if (consp a) | |
82 | (eq (car a) 'bigneg) | |
83 | (< a 0))) | |
84 | ||
85 | (defsubst Math-integer-posp (a) | |
86 | (if (consp a) | |
87 | (eq (car a) 'bigpos) | |
88 | (> a 0))) | |
89 | ||
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))) | |
98 | ||
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)))))))) | |
105 | ||
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))) | |
114 | ||
115 | (defsubst Math-integerp (a) | |
116 | (or (not (consp a)) | |
117 | (memq (car a) '(bigpos bigneg)))) | |
118 | ||
119 | (defsubst Math-natnump (a) | |
120 | (if (consp a) | |
121 | (eq (car a) 'bigpos) | |
122 | (>= a 0))) | |
123 | ||
124 | (defsubst Math-ratp (a) | |
125 | (or (not (consp a)) | |
126 | (memq (car a) '(bigpos bigneg frac)))) | |
127 | ||
128 | (defsubst Math-realp (a) | |
129 | (or (not (consp a)) | |
130 | (memq (car a) '(bigpos bigneg frac float)))) | |
131 | ||
132 | (defsubst Math-anglep (a) | |
133 | (or (not (consp a)) | |
134 | (memq (car a) '(bigpos bigneg frac float hms)))) | |
135 | ||
136 | (defsubst Math-numberp (a) | |
137 | (or (not (consp a)) | |
138 | (memq (car a) '(bigpos bigneg frac float cplx polar)))) | |
139 | ||
140 | (defsubst Math-scalarp (a) | |
141 | (or (not (consp a)) | |
142 | (memq (car a) '(bigpos bigneg frac float cplx polar hms)))) | |
143 | ||
144 | (defsubst Math-vectorp (a) | |
145 | (and (consp a) (eq (car a) 'vec))) | |
146 | ||
147 | (defsubst Math-messy-integerp (a) | |
148 | (and (consp a) | |
149 | (eq (car a) 'float) | |
150 | (>= (nth 2 a) 0))) | |
151 | ||
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)))) | |
156 | ||
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)))) | |
136211a9 | 162 | |
3e3b3c7e CW |
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))) | |
170 | ||
171 | (defsubst Math-equal (a b) | |
172 | (= (math-compare a b) 0)) | |
173 | ||
174 | (defsubst Math-lessp (a b) | |
175 | (= (math-compare a b) -1)) | |
176 | ||
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)))) | |
181 | ||
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)))) | |
187 | ||
188 | (defsubst Math-bignum-test (a) ; [B N; B s; b b] | |
189 | (if (consp a) | |
190 | a | |
191 | (math-bignum a))) | |
192 | ||
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)))) | |
199 | ||
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)))) | |
136211a9 | 206 | |
f50dfd02 JB |
207 | (provide 'calc-macs) |
208 | ||
bf77c646 | 209 | ;;; calc-macs.el ends here |