(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / calc / calc-macs.el
blob1004a8f1f5634b73d0eb428a9954d1d4f7b33625
1 ;;; calc-macs.el --- important macros for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2005 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <belanger@truman.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY. No author or distributor
12 ;; accepts responsibility to anyone for the consequences of using it
13 ;; or for whether it serves any particular purpose or works at all,
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public
15 ;; License for full details.
17 ;; Everyone is granted permission to copy, modify and redistribute
18 ;; GNU Emacs, but only under the conditions described in the
19 ;; GNU Emacs General Public License. A copy of this license is
20 ;; supposed to have been given to you along with GNU Emacs so you
21 ;; can know your rights and responsibilities. It should be in a
22 ;; file named COPYING. Among other things, the copyright notice
23 ;; and this notice must be preserved on all copies.
25 ;;; Commentary:
27 ;;; Code:
29 (defmacro calc-wrapper (&rest body)
30 `(calc-do (function (lambda ()
31 ,@body))))
33 (defmacro calc-slow-wrapper (&rest body)
34 `(calc-do
35 (function (lambda () ,@body)) (point)))
37 (defmacro math-showing-full-precision (form)
38 `(let ((calc-float-format calc-full-float-format))
39 ,form))
41 (defmacro math-with-extra-prec (delta &rest body)
42 `(math-normalize
43 (let ((calc-internal-prec (+ calc-internal-prec ,delta)))
44 ,@body)))
46 (defmacro math-working (msg arg) ; [Public]
47 `(if (eq calc-display-working-message 'lots)
48 (math-do-working ,msg ,arg)))
50 (defmacro calc-with-default-simplification (&rest body)
51 `(let ((calc-simplify-mode (and (not (memq calc-simplify-mode '(none num)))
52 calc-simplify-mode)))
53 ,@body))
55 (defmacro calc-with-trail-buffer (&rest body)
56 `(let ((save-buf (current-buffer))
57 (calc-command-flags nil))
58 (with-current-buffer (calc-trail-display t)
59 (progn
60 (goto-char calc-trail-pointer)
61 ,@body))))
63 ;;; Faster in-line version zerop, normalized values only.
64 (defsubst Math-zerop (a) ; [P N]
65 (if (consp a)
66 (and (not (memq (car a) '(bigpos bigneg)))
67 (if (eq (car a) 'float)
68 (eq (nth 1 a) 0)
69 (math-zerop a)))
70 (eq a 0)))
72 (defsubst Math-integer-negp (a)
73 (if (consp a)
74 (eq (car a) 'bigneg)
75 (< a 0)))
77 (defsubst Math-integer-posp (a)
78 (if (consp a)
79 (eq (car a) 'bigpos)
80 (> a 0)))
82 (defsubst Math-negp (a)
83 (if (consp a)
84 (or (eq (car a) 'bigneg)
85 (and (not (eq (car a) 'bigpos))
86 (if (memq (car a) '(frac float))
87 (Math-integer-negp (nth 1 a))
88 (math-negp a))))
89 (< a 0)))
91 (defsubst Math-looks-negp (a) ; [P x] [Public]
92 (or (Math-negp a)
93 (and (consp a) (or (eq (car a) 'neg)
94 (and (memq (car a) '(* /))
95 (or (math-looks-negp (nth 1 a))
96 (math-looks-negp (nth 2 a))))))))
98 (defsubst Math-posp (a)
99 (if (consp a)
100 (or (eq (car a) 'bigpos)
101 (and (not (eq (car a) 'bigneg))
102 (if (memq (car a) '(frac float))
103 (Math-integer-posp (nth 1 a))
104 (math-posp a))))
105 (> a 0)))
107 (defsubst Math-integerp (a)
108 (or (not (consp a))
109 (memq (car a) '(bigpos bigneg))))
111 (defsubst Math-natnump (a)
112 (if (consp a)
113 (eq (car a) 'bigpos)
114 (>= a 0)))
116 (defsubst Math-ratp (a)
117 (or (not (consp a))
118 (memq (car a) '(bigpos bigneg frac))))
120 (defsubst Math-realp (a)
121 (or (not (consp a))
122 (memq (car a) '(bigpos bigneg frac float))))
124 (defsubst Math-anglep (a)
125 (or (not (consp a))
126 (memq (car a) '(bigpos bigneg frac float hms))))
128 (defsubst Math-numberp (a)
129 (or (not (consp a))
130 (memq (car a) '(bigpos bigneg frac float cplx polar))))
132 (defsubst Math-scalarp (a)
133 (or (not (consp a))
134 (memq (car a) '(bigpos bigneg frac float cplx polar hms))))
136 (defsubst Math-vectorp (a)
137 (and (consp a) (eq (car a) 'vec)))
139 (defsubst Math-messy-integerp (a)
140 (and (consp a)
141 (eq (car a) 'float)
142 (>= (nth 2 a) 0)))
144 (defsubst Math-objectp (a) ; [Public]
145 (or (not (consp a))
146 (memq (car a)
147 '(bigpos bigneg frac float cplx polar hms date sdev intv mod))))
149 (defsubst Math-objvecp (a) ; [Public]
150 (or (not (consp a))
151 (memq (car a)
152 '(bigpos bigneg frac float cplx polar hms date
153 sdev intv mod vec))))
155 ;;; Compute the negative of A. [O O; o o] [Public]
156 (defsubst Math-integer-neg (a)
157 (if (consp a)
158 (if (eq (car a) 'bigpos)
159 (cons 'bigneg (cdr a))
160 (cons 'bigpos (cdr a)))
161 (- a)))
163 (defsubst Math-equal (a b)
164 (= (math-compare a b) 0))
166 (defsubst Math-lessp (a b)
167 (= (math-compare a b) -1))
169 (defsubst Math-primp (a)
170 (or (not (consp a))
171 (memq (car a) '(bigpos bigneg frac float cplx polar
172 hms date mod var))))
174 (defsubst Math-num-integerp (a)
175 (or (not (consp a))
176 (memq (car a) '(bigpos bigneg))
177 (and (eq (car a) 'float)
178 (>= (nth 2 a) 0))))
180 (defsubst Math-bignum-test (a) ; [B N; B s; b b]
181 (if (consp a)
183 (math-bignum a)))
185 (defsubst Math-equal-int (a b)
186 (or (eq a b)
187 (and (consp a)
188 (eq (car a) 'float)
189 (eq (nth 1 a) b)
190 (= (nth 2 a) 0))))
192 (defsubst Math-natnum-lessp (a b)
193 (if (consp a)
194 (and (consp b)
195 (= (math-compare-bignum (cdr a) (cdr b)) -1))
196 (or (consp b)
197 (< a b))))
199 (provide 'calc-macs)
201 ;;; arch-tag: 08ba8ec2-fcff-4b80-a079-ec661bdb057e
202 ;;; calc-macs.el ends here