* progmodes/sql.el (sql-mode-sqlite-font-lock-keywords): Added
[bpt/emacs.git] / lisp / calc / calc-macs.el
CommitLineData
3e3b3c7e
CW
1;;; calc-macs.el --- important macros for Calc
2
58ba2f8f 3;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3e3b3c7e
CW
5
6;; Author: David Gillespie <daveg@synaptics.com>
e8fff8ed 7;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
136211a9
EZ
8
9;; This file is part of GNU Emacs.
10
662c9c64 11;; GNU Emacs is free software: you can redistribute it and/or modify
7c671b23 12;; it under the terms of the GNU General Public License as published by
662c9c64
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
7c671b23 15
136211a9 16;; GNU Emacs is distributed in the hope that it will be useful,
7c671b23
GM
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.
20
21;; You should have received a copy of the GNU General Public License
662c9c64 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
136211a9 23
3e3b3c7e
CW
24;;; Commentary:
25
26;;; Code:
136211a9 27
84309b3b
JB
28;; Declare functions which are defined elsewhere.
29(declare-function math-zerop "calc-misc" (a))
30(declare-function math-negp "calc-misc" (a))
31(declare-function math-looks-negp "calc-misc" (a))
32(declare-function math-posp "calc-misc" (a))
33(declare-function math-compare "calc-ext" (a b))
34(declare-function math-bignum "calc" (a))
35(declare-function math-compare-bignum "calc-ext" (a b))
36
37
136211a9 38(defmacro calc-wrapper (&rest body)
3e3b3c7e
CW
39 `(calc-do (function (lambda ()
40 ,@body))))
136211a9 41
136211a9 42(defmacro calc-slow-wrapper (&rest body)
3e3b3c7e 43 `(calc-do
e7905671 44 (function (lambda () ,@body)) (point)))
136211a9 45
3e3b3c7e
CW
46(defmacro math-showing-full-precision (form)
47 `(let ((calc-float-format calc-full-float-format))
48 ,form))
136211a9
EZ
49
50(defmacro math-with-extra-prec (delta &rest body)
3e3b3c7e
CW
51 `(math-normalize
52 (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
53 ,@body)))
136211a9 54
3e3b3c7e
CW
55(defmacro math-working (msg arg) ; [Public]
56 `(if (eq calc-display-working-message 'lots)
57 (math-do-working ,msg ,arg)))
136211a9 58
061b2cc1 59(defmacro calc-with-default-simplification (&rest body)
3e3b3c7e
CW
60 `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
61 calc-simplify-mode)))
62 ,@body))
136211a9 63
3e3b3c7e
CW
64(defmacro calc-with-trail-buffer (&rest body)
65 `(let ((save-buf (current-buffer))
66 (calc-command-flags nil))
67 (with-current-buffer (calc-trail-display t)
68 (progn
69 (goto-char calc-trail-pointer)
70 ,@body))))
136211a9 71
3e3b3c7e
CW
72;;; Faster in-line version zerop, normalized values only.
73(defsubst Math-zerop (a) ; [P N]
74 (if (consp a)
75 (and (not (memq (car a) '(bigpos bigneg)))
76 (if (eq (car a) 'float)
77 (eq (nth 1 a) 0)
78 (math-zerop a)))
79 (eq a 0)))
80
81(defsubst Math-integer-negp (a)
82 (if (consp a)
83 (eq (car a) 'bigneg)
84 (< a 0)))
85
86(defsubst Math-integer-posp (a)
87 (if (consp a)
88 (eq (car a) 'bigpos)
89 (> a 0)))
90
91(defsubst Math-negp (a)
92 (if (consp a)
93 (or (eq (car a) 'bigneg)
94 (and (not (eq (car a) 'bigpos))
95 (if (memq (car a) '(frac float))
96 (Math-integer-negp (nth 1 a))
97 (math-negp a))))
98 (< a 0)))
99
100(defsubst Math-looks-negp (a) ; [P x] [Public]
101 (or (Math-negp a)
102 (and (consp a) (or (eq (car a) 'neg)
103 (and (memq (car a) '(* /))
104 (or (math-looks-negp (nth 1 a))
105 (math-looks-negp (nth 2 a))))))))
106
107(defsubst Math-posp (a)
108 (if (consp a)
109 (or (eq (car a) 'bigpos)
110 (and (not (eq (car a) 'bigneg))
111 (if (memq (car a) '(frac float))
112 (Math-integer-posp (nth 1 a))
113 (math-posp a))))
114 (> a 0)))
115
116(defsubst Math-integerp (a)
117 (or (not (consp a))
118 (memq (car a) '(bigpos bigneg))))
119
120(defsubst Math-natnump (a)
121 (if (consp a)
122 (eq (car a) 'bigpos)
123 (>= a 0)))
124
125(defsubst Math-ratp (a)
126 (or (not (consp a))
127 (memq (car a) '(bigpos bigneg frac))))
128
129(defsubst Math-realp (a)
130 (or (not (consp a))
131 (memq (car a) '(bigpos bigneg frac float))))
132
133(defsubst Math-anglep (a)
134 (or (not (consp a))
135 (memq (car a) '(bigpos bigneg frac float hms))))
136
137(defsubst Math-numberp (a)
138 (or (not (consp a))
139 (memq (car a) '(bigpos bigneg frac float cplx polar))))
140
141(defsubst Math-scalarp (a)
142 (or (not (consp a))
143 (memq (car a) '(bigpos bigneg frac float cplx polar hms))))
144
145(defsubst Math-vectorp (a)
146 (and (consp a) (eq (car a) 'vec)))
147
148(defsubst Math-messy-integerp (a)
149 (and (consp a)
150 (eq (car a) 'float)
151 (>= (nth 2 a) 0)))
152
153(defsubst Math-objectp (a) ; [Public]
154 (or (not (consp a))
155 (memq (car a)
156 '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
157
158(defsubst Math-objvecp (a) ; [Public]
159 (or (not (consp a))
160 (memq (car a)
161 '(bigpos bigneg frac float cplx polar hms date
162 sdev intv mod vec))))
136211a9 163
3e3b3c7e
CW
164;;; Compute the negative of A. [O O; o o] [Public]
165(defsubst Math-integer-neg (a)
166 (if (consp a)
167 (if (eq (car a) 'bigpos)
168 (cons 'bigneg (cdr a))
169 (cons 'bigpos (cdr a)))
170 (- a)))
171
172(defsubst Math-equal (a b)
173 (= (math-compare a b) 0))
174
175(defsubst Math-lessp (a b)
176 (= (math-compare a b) -1))
177
178(defsubst Math-primp (a)
179 (or (not (consp a))
180 (memq (car a) '(bigpos bigneg frac float cplx polar
181 hms date mod var))))
182
183(defsubst Math-num-integerp (a)
184 (or (not (consp a))
185 (memq (car a) '(bigpos bigneg))
186 (and (eq (car a) 'float)
187 (>= (nth 2 a) 0))))
188
189(defsubst Math-bignum-test (a) ; [B N; B s; b b]
190 (if (consp a)
191 a
192 (math-bignum a)))
193
194(defsubst Math-equal-int (a b)
195 (or (eq a b)
196 (and (consp a)
197 (eq (car a) 'float)
198 (eq (nth 1 a) b)
199 (= (nth 2 a) 0))))
200
201(defsubst Math-natnum-lessp (a b)
202 (if (consp a)
203 (and (consp b)
204 (= (math-compare-bignum (cdr a) (cdr b)) -1))
205 (or (consp b)
206 (< a b))))
136211a9 207
f50dfd02
JB
208(provide 'calc-macs)
209
cbee283d 210;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
bf77c646 211;;; calc-macs.el ends here