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)
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.
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 ()
44 (defmacro calc-slow-wrapper (&rest body)
46 (function (lambda () ,@body)) (point)))
48 (defmacro math-showing-full-precision (form)
49 `(let ((calc-float-format calc-full-float-format))
52 (defmacro math-with-extra-prec (delta &rest body)
54 (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
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)))
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)
71 (goto-char calc-trail-pointer)
74 ;;; Faster in-line version zerop, normalized values only.
75 (defsubst Math-zerop (a) ; [P N]
77 (and (not (memq (car a) '(bigpos bigneg)))
78 (if (eq (car a) 'float)
83 (defsubst Math-integer-negp (a)
88 (defsubst Math-integer-posp (a)
93 (defsubst Math-negp (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))
102 (defsubst Math-looks-negp (a) ; [P x] [Public]
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)
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))
118 (defsubst Math-integerp (a)
120 (memq (car a) '(bigpos bigneg))))
122 (defsubst Math-natnump (a)
127 (defsubst Math-ratp (a)
129 (memq (car a) '(bigpos bigneg frac))))
131 (defsubst Math-realp (a)
133 (memq (car a) '(bigpos bigneg frac float))))
135 (defsubst Math-anglep (a)
137 (memq (car a) '(bigpos bigneg frac float hms))))
139 (defsubst Math-numberp (a)
141 (memq (car a) '(bigpos bigneg frac float cplx polar))))
143 (defsubst Math-scalarp (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)
155 (defsubst Math-objectp (a) ; [Public]
158 '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
160 (defsubst Math-objvecp (a) ; [Public]
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)
169 (if (eq (car a) 'bigpos)
170 (cons 'bigneg (cdr a))
171 (cons 'bigpos (cdr 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)
182 (memq (car a) '(bigpos bigneg frac float cplx polar
185 (defsubst Math-num-integerp (a)
187 (memq (car a) '(bigpos bigneg))
188 (and (eq (car a) 'float)
191 (defsubst Math-bignum-test (a) ; [B N; B s; b b]
196 (defsubst Math-equal-int (a b)
203 (defsubst Math-natnum-lessp (a b)
206 (= (math-compare-bignum (cdr a) (cdr b)) -1))
212 ;;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
213 ;;; calc-macs.el ends here