1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
;; Calculator for GNU Emacs, part I [calc-macs.el]
;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; This file is part of GNU Emacs.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY. No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing. Refer to the GNU Emacs General Public
;; License for full details.
;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License. A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities. It should be in a
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
(provide 'calc-macs)
(defun calc-need-macros () nil)
(defmacro calc-record-compilation-date-macro ()
(` (setq calc-installed-date (, (concat (current-time-string)
" by "
(user-full-name)))))
)
(defmacro calc-wrapper (&rest body)
(list 'calc-do (list 'function (append (list 'lambda ()) body)))
)
;; We use "point" here to generate slightly smaller byte-code than "t".
(defmacro calc-slow-wrapper (&rest body)
(list 'calc-do (list 'function (append (list 'lambda ()) body)) (point))
)
(defmacro math-showing-full-precision (body)
(list 'let
'((calc-float-format calc-full-float-format))
body)
)
(defmacro math-with-extra-prec (delta &rest body)
(` (math-normalize
(let ((calc-internal-prec (+ calc-internal-prec (, delta))))
(,@ body))))
)
;;; Faster in-line version zerop, normalized values only.
(defmacro Math-zerop (a) ; [P N]
(` (if (consp (, a))
(and (not (memq (car (, a)) '(bigpos bigneg)))
(if (eq (car (, a)) 'float)
(eq (nth 1 (, a)) 0)
(math-zerop (, a))))
(eq (, a) 0)))
)
(defmacro Math-integer-negp (a)
(` (if (consp (, a))
(eq (car (, a)) 'bigneg)
(< (, a) 0)))
)
(defmacro Math-integer-posp (a)
(` (if (consp (, a))
(eq (car (, a)) 'bigpos)
(> (, a) 0)))
)
(defmacro Math-negp (a)
(` (if (consp (, a))
(or (eq (car (, a)) 'bigneg)
(and (not (eq (car (, a)) 'bigpos))
(if (memq (car (, a)) '(frac float))
(Math-integer-negp (nth 1 (, a)))
(math-negp (, a)))))
(< (, a) 0)))
)
(defmacro Math-looks-negp (a) ; [P x] [Public]
(` (or (Math-negp (, a))
(and (consp (, a)) (or (eq (car (, a)) 'neg)
(and (memq (car (, a)) '(* /))
(or (math-looks-negp (nth 1 (, a)))
(math-looks-negp (nth 2 (, a)))))))))
)
(defmacro Math-posp (a)
(` (if (consp (, a))
(or (eq (car (, a)) 'bigpos)
(and (not (eq (car (, a)) 'bigneg))
(if (memq (car (, a)) '(frac float))
(Math-integer-posp (nth 1 (, a)))
(math-posp (, a)))))
(> (, a) 0)))
)
(defmacro Math-integerp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg))))
)
(defmacro Math-natnump (a)
(` (if (consp (, a))
(eq (car (, a)) 'bigpos)
(>= (, a) 0)))
)
(defmacro Math-ratp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg frac))))
)
(defmacro Math-realp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg frac float))))
)
(defmacro Math-anglep (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg frac float hms))))
)
(defmacro Math-numberp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg frac float cplx polar))))
)
(defmacro Math-scalarp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg frac float cplx polar hms))))
)
(defmacro Math-vectorp (a)
(` (and (consp (, a)) (eq (car (, a)) 'vec)))
)
(defmacro Math-messy-integerp (a)
(` (and (consp (, a))
(eq (car (, a)) 'float)
(>= (nth 2 (, a)) 0)))
)
(defmacro Math-objectp (a) ; [Public]
(` (or (not (consp (, a)))
(memq (car (, a))
'(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
)
(defmacro Math-objvecp (a) ; [Public]
(` (or (not (consp (, a)))
(memq (car (, a))
'(bigpos bigneg frac float cplx polar hms date
sdev intv mod vec))))
)
;;; Compute the negative of A. [O O; o o] [Public]
(defmacro Math-integer-neg (a)
(` (if (consp (, a))
(if (eq (car (, a)) 'bigpos)
(cons 'bigneg (cdr (, a)))
(cons 'bigpos (cdr (, a))))
(- (, a))))
)
(defmacro Math-equal (a b)
(` (= (math-compare (, a) (, b)) 0))
)
(defmacro Math-lessp (a b)
(` (= (math-compare (, a) (, b)) -1))
)
(defmacro math-working (msg arg) ; [Public]
(` (if (eq calc-display-working-message 'lots)
(math-do-working (, msg) (, arg))))
)
(defmacro calc-with-default-simplification (body)
(list 'let
'((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
calc-simplify-mode)))
body)
)
(defmacro Math-primp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg frac float cplx polar
hms date mod var))))
)
(defmacro calc-with-trail-buffer (&rest body)
(` (let ((save-buf (current-buffer))
(calc-command-flags nil))
(unwind-protect
(, (append '(progn
(set-buffer (calc-trail-display t))
(goto-char calc-trail-pointer))
body))
(set-buffer save-buf))))
)
(defmacro Math-num-integerp (a)
(` (or (not (consp (, a)))
(memq (car (, a)) '(bigpos bigneg))
(and (eq (car (, a)) 'float)
(>= (nth 2 (, a)) 0))))
)
(defmacro Math-bignum-test (a) ; [B N; B s; b b]
(` (if (consp (, a))
(, a)
(math-bignum (, a))))
)
(defmacro Math-equal-int (a b)
(` (or (eq (, a) (, b))
(and (consp (, a))
(eq (car (, a)) 'float)
(eq (nth 1 (, a)) (, b))
(= (nth 2 (, a)) 0))))
)
(defmacro Math-natnum-lessp (a b)
(` (if (consp (, a))
(and (consp (, b))
(= (math-compare-bignum (cdr (, a)) (cdr (, b))) -1))
(or (consp (, b))
(< (, a) (, b)))))
)
(defmacro math-format-radix-digit (a) ; [X D]
(` (aref math-radix-digits (, a)))
)
|