Mercurial > emacs
annotate lisp/calc/calc-misc.el @ 72247:2d16125405b4
Docstring style and grammar tweaks; nfc.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Wed, 02 Aug 2006 22:51:44 +0000 |
parents | 6bf177f8065b |
children | 7a3f13e2dd57 c5406394f567 |
rev | line source |
---|---|
63610 | 1 ;;; calc-misc.el --- miscellaneous functions for Calc |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
2 |
64325
1db49616ce05
Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
63610
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004 |
68636
6bf177f8065b
Update copyright year.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
67190
diff
changeset
|
4 ;; 2005, 2006 Free Software Foundation, Inc. |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
5 |
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
6 ;; Author: David Gillespie <daveg@synaptics.com> |
58480
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
7 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
16 ;; License for full details. | |
17 | |
18 ;; Everyone is granted permission to copy, modify and redistribute | |
19 ;; GNU Emacs, but only under the conditions described in the | |
20 ;; GNU Emacs General Public License. A copy of this license is | |
21 ;; supposed to have been given to you along with GNU Emacs so you | |
22 ;; can know your rights and responsibilities. It should be in a | |
23 ;; file named COPYING. Among other things, the copyright notice | |
24 ;; and this notice must be preserved on all copies. | |
25 | |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; This file is autoloaded from calc.el. | |
58664
f23c98cc77a1
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58613
diff
changeset
|
31 |
40785 | 32 (require 'calc) |
33 (require 'calc-macs) | |
34 | |
35 (defun calc-dispatch-help (arg) | |
67190
655ce2fe3aa6
(calc-dispatch-help): Update docstring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
66480
diff
changeset
|
36 "C-x* is a prefix key sequence; follow it with one of these letters: |
40785 | 37 |
38 For turning Calc on and off: | |
39 C calc. Start the Calculator in a window at the bottom of the screen. | |
40 O calc-other-window. Start the Calculator but don't select its window. | |
41 B calc-big-or-small. Control whether to use the full Emacs screen for Calc. | |
42 Q quick-calc. Use the Calculator in the minibuffer. | |
43 K calc-keypad. Start the Calculator in keypad mode (X window system only). | |
44 E calc-embedded. Use the Calculator on a formula in this editing buffer. | |
45 J calc-embedded-select. Like E, but select appropriate half of => or :=. | |
46 W calc-embedded-word. Like E, but activate a single word, i.e., a number. | |
47 Z calc-user-invocation. Invoke Calc in the way you defined with `Z I' cmd. | |
48 X calc-quit. Turn Calc off. | |
49 | |
50 For moving data into and out of Calc: | |
51 G calc-grab-region. Grab the region defined by mark and point into Calc. | |
52 R calc-grab-rectangle. Grab the rectangle defined by mark, point into Calc. | |
53 : calc-grab-sum-down. Grab a rectangle and sum the columns. | |
54 _ calc-grab-sum-across. Grab a rectangle and sum the rows. | |
55 Y calc-copy-to-buffer. Copy a value from the stack into the editing buffer. | |
56 | |
57 For use with Embedded mode: | |
58 A calc-embedded-activate. Find and activate all :='s and =>'s in buffer. | |
59 D calc-embedded-duplicate. Make a copy of this formula and select it. | |
60 F calc-embedded-new-formula. Insert a new formula at current point. | |
61 N calc-embedded-next. Advance cursor to next known formula in buffer. | |
62 P calc-embedded-previous. Advance cursor to previous known formula. | |
63 U calc-embedded-update-formula. Re-evaluate formula at point. | |
64 ` calc-embedded-edit. Use calc-edit to edit formula at point. | |
65 | |
66 Documentation: | |
67 I calc-info. Read the Calculator manual in the Emacs Info system. | |
68 T calc-tutorial. Run the Calculator Tutorial using the Emacs Info system. | |
69 S calc-summary. Read the Summary from the Calculator manual in Info. | |
70 | |
71 Miscellaneous: | |
72 L calc-load-everything. Load all parts of the Calculator into memory. | |
73 M read-kbd-macro. Read a region of keystroke names as a keyboard macro. | |
74 0 (zero) calc-reset. Reset Calc stack and modes to default state. | |
75 | |
67190
655ce2fe3aa6
(calc-dispatch-help): Update docstring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
66480
diff
changeset
|
76 Press `*' twice (`C-x * *') to turn Calc on or off using the same |
655ce2fe3aa6
(calc-dispatch-help): Update docstring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
66480
diff
changeset
|
77 Calc user interface as before (either C-x * C or C-x * K; initially C-x * C). |
655ce2fe3aa6
(calc-dispatch-help): Update docstring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
66480
diff
changeset
|
78 " |
40785 | 79 (interactive "P") |
80 (calc-check-defines) | |
81 (if calc-dispatch-help | |
82 (progn | |
83 (save-window-excursion | |
84 (describe-function 'calc-dispatch-help) | |
85 (let ((win (get-buffer-window "*Help*"))) | |
86 (if win | |
87 (let (key) | |
88 (select-window win) | |
89 (while (progn | |
90 (message "Calc options: Calc, Keypad, ... %s" | |
91 "press SPC, DEL to scroll, C-g to cancel") | |
92 (memq (car (setq key (calc-read-key t))) | |
93 '(? ?\C-h ?\C-? ?\C-v ?\M-v))) | |
94 (condition-case err | |
95 (if (memq (car key) '(? ?\C-v)) | |
96 (scroll-up) | |
97 (scroll-down)) | |
98 (error (beep)))) | |
99 (calc-unread-command (cdr key)))))) | |
100 (calc-do-dispatch nil)) | |
101 (let ((calc-dispatch-help t)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
102 (calc-do-dispatch arg)))) |
40785 | 103 |
104 | |
105 (defun calc-big-or-small (arg) | |
106 "Toggle Calc between full-screen and regular mode." | |
107 (interactive "P") | |
108 (let ((cwin (get-buffer-window "*Calculator*")) | |
109 (twin (get-buffer-window "*Calc Trail*")) | |
110 (kwin (get-buffer-window "*Calc Keypad*"))) | |
111 (if cwin | |
112 (setq calc-full-mode | |
113 (if kwin | |
40998
ee9c2872370b
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
114 (and twin (eq (window-width twin) (frame-width))) |
ee9c2872370b
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
115 (eq (window-height cwin) (1- (frame-height)))))) |
40785 | 116 (setq calc-full-mode (if arg |
117 (> (prefix-numeric-value arg) 0) | |
118 (not calc-full-mode))) | |
119 (if kwin | |
120 (progn | |
121 (calc-quit) | |
122 (calc-do-keypad calc-full-mode nil)) | |
123 (if cwin | |
124 (progn | |
125 (calc-quit) | |
126 (calc nil calc-full-mode nil)))) | |
127 (message (if calc-full-mode | |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
128 "Now using full screen for Calc" |
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
129 "Now using partial screen for Calc")))) |
40785 | 130 |
57711
d9073880a6e4
(calc-other-window): Use an extra argument instead of `interactive-p'.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57430
diff
changeset
|
131 (defun calc-other-window (&optional interactive) |
40785 | 132 "Invoke the Calculator in another window." |
57711
d9073880a6e4
(calc-other-window): Use an extra argument instead of `interactive-p'.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57430
diff
changeset
|
133 (interactive "p") |
40785 | 134 (if (memq major-mode '(calc-mode calc-trail-mode)) |
135 (progn | |
136 (other-window 1) | |
137 (if (memq major-mode '(calc-mode calc-trail-mode)) | |
138 (other-window 1))) | |
139 (if (get-buffer-window "*Calculator*") | |
140 (calc-quit) | |
141 (let ((win (selected-window))) | |
57711
d9073880a6e4
(calc-other-window): Use an extra argument instead of `interactive-p'.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57430
diff
changeset
|
142 (calc nil win interactive))))) |
40785 | 143 |
144 (defun another-calc () | |
145 "Create another, independent Calculator buffer." | |
146 (interactive) | |
147 (if (eq major-mode 'calc-mode) | |
148 (mapcar (function | |
149 (lambda (v) | |
150 (set-default v (symbol-value v)))) calc-local-var-list)) | |
151 (set-buffer (generate-new-buffer "*Calculator*")) | |
152 (pop-to-buffer (current-buffer)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
153 (calc-mode)) |
40785 | 154 |
155 (defun calc-info () | |
156 "Run the Emacs Info system on the Calculator documentation." | |
157 (interactive) | |
158 (select-window (get-largest-window)) | |
41359
5042a5269efd
(calc-info): Don't perform voodoo, just (info "Calc").
Colin Walters <walters@gnu.org>
parents:
41267
diff
changeset
|
159 (info "Calc")) |
40785 | 160 |
57430
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
161 (defun calc-info-goto-node (node) |
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
162 "Go to a node in the Calculator info documentation." |
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
163 (interactive) |
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
164 (select-window (get-largest-window)) |
62829
a91bfc189888
(calc-info-goto-node): Use info instead of Info-goto-node.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62442
diff
changeset
|
165 (info (concat "(Calc)" node))) |
57430
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
166 |
40785 | 167 (defun calc-tutorial () |
168 "Run the Emacs Info system on the Calculator Tutorial." | |
169 (interactive) | |
170 (if (get-buffer-window "*Calculator*") | |
171 (calc-quit)) | |
57430
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
172 (calc-info-goto-node "Interactive Tutorial") |
40785 | 173 (calc-other-window) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
174 (message "Welcome to the Calc Tutorial!")) |
40785 | 175 |
176 (defun calc-info-summary () | |
177 "Run the Emacs Info system on the Calculator Summary." | |
178 (interactive) | |
57430
f4e473491598
(calc-info-goto-node): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
179 (calc-info-goto-node "Summary")) |
40785 | 180 |
181 (defun calc-help () | |
182 (interactive) | |
183 (let ((msgs (append | |
184 '("Press `h' for complete help; press `?' repeatedly for a summary" | |
185 "Letter keys: Negate; Precision; Yank; Why; Xtended cmd; Quit" | |
186 "Letter keys: SHIFT + Undo, reDo; Keep-args; Inverse, Hyperbolic" | |
187 "Letter keys: SHIFT + sQrt; Sin, Cos, Tan; Exp, Ln, logB" | |
188 "Letter keys: SHIFT + Floor, Round; Abs, conJ, arG; Pi" | |
189 "Letter keys: SHIFT + Num-eval; More-recn; eXec-kbd-macro" | |
190 "Other keys: +, -, *, /, ^, \\ (int div), : (frac div)" | |
191 "Other keys: & (1/x), | (concat), % (modulo), ! (factorial)" | |
192 "Other keys: ' (alg-entry), = (eval), ` (edit); M-RET (last-args)" | |
193 "Other keys: SPC/RET (enter/dup), LFD (over); < > (scroll horiz)" | |
194 "Other keys: DEL (drop), M-DEL (drop-above); { } (scroll vert)" | |
195 "Other keys: TAB (swap/roll-dn), M-TAB (roll-up)" | |
196 "Other keys: [ , ; ] (vector), ( , ) (complex), ( ; ) (polar)" | |
197 "Prefix keys: Algebra, Binary/business, Convert, Display" | |
198 "Prefix keys: Functions, Graphics, Help, J (select)" | |
199 "Prefix keys: Kombinatorics/statistics, Modes, Store/recall" | |
200 "Prefix keys: Trail/time, Units/statistics, Vector/matrix" | |
201 "Prefix keys: Z (user), SHIFT + Z (define)" | |
202 "Prefix keys: prefix + ? gives further help for that prefix") | |
203 (list (format | |
204 " Calc %s by Dave Gillespie, daveg@synaptics.com" | |
205 calc-version))))) | |
206 (if calc-full-help-flag | |
207 msgs | |
208 (if (or calc-inverse-flag calc-hyperbolic-flag) | |
209 (if calc-inverse-flag | |
210 (if calc-hyperbolic-flag | |
211 (calc-inv-hyp-prefix-help) | |
212 (calc-inverse-prefix-help)) | |
213 (calc-hyperbolic-prefix-help)) | |
214 (setq calc-help-phase | |
215 (if (eq this-command last-command) | |
216 (% (1+ calc-help-phase) (1+ (length msgs))) | |
217 0)) | |
218 (let ((msg (nth calc-help-phase msgs))) | |
219 (message "%s" (if msg | |
220 (concat msg ":" | |
221 (make-string (- (apply 'max | |
222 (mapcar 'length | |
223 msgs)) | |
224 (length msg)) 32) | |
225 " [?=MORE]") | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
226 ""))))))) |
40785 | 227 |
228 | |
229 | |
230 | |
231 ;;;; Stack and buffer management. | |
232 | |
58543
129486947645
(calc-last-why-command): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58480
diff
changeset
|
233 ;; The variable calc-last-why-command is set in calc-do-handly-whys |
129486947645
(calc-last-why-command): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58480
diff
changeset
|
234 ;; and used in calc-why (in calc-stuff.el). |
129486947645
(calc-last-why-command): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58480
diff
changeset
|
235 (defvar calc-last-why-command) |
40785 | 236 |
237 (defun calc-do-handle-whys () | |
238 (setq calc-why (sort calc-next-why | |
239 (function | |
240 (lambda (x y) | |
241 (and (eq (car x) '*) (not (eq (car y) '*)))))) | |
242 calc-next-why nil) | |
243 (if (and calc-why (or (eq calc-auto-why t) | |
244 (and (eq (car (car calc-why)) '*) | |
245 calc-auto-why))) | |
246 (progn | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
247 (require 'calc-ext) |
40785 | 248 (calc-explain-why (car calc-why) |
249 (if (eq calc-auto-why t) | |
250 (cdr calc-why) | |
251 (if calc-auto-why | |
252 (eq (car (nth 1 calc-why)) '*)))) | |
253 (setq calc-last-why-command this-command) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
254 (calc-clear-command-flag 'clear-message)))) |
40785 | 255 |
256 (defun calc-record-why (&rest stuff) | |
257 (if (eq (car stuff) 'quiet) | |
258 (setq stuff (cdr stuff)) | |
259 (if (and (symbolp (car stuff)) | |
260 (cdr stuff) | |
261 (or (Math-objectp (nth 1 stuff)) | |
262 (and (Math-vectorp (nth 1 stuff)) | |
263 (math-constp (nth 1 stuff))) | |
264 (math-infinitep (nth 1 stuff)))) | |
265 (setq stuff (cons '* stuff)) | |
266 (if (and (stringp (car stuff)) | |
267 (string-match "\\`\\*" (car stuff))) | |
268 (setq stuff (cons '* (cons (substring (car stuff) 1) | |
269 (cdr stuff))))))) | |
270 (setq calc-next-why (cons stuff calc-next-why)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
271 nil) |
40785 | 272 |
273 ;;; True if A is a constant or vector of constants. [P x] [Public] | |
274 (defun math-constp (a) | |
275 (or (Math-scalarp a) | |
276 (and (memq (car a) '(sdev intv mod vec)) | |
277 (progn | |
278 (while (and (setq a (cdr a)) | |
279 (or (Math-scalarp (car a)) ; optimization | |
280 (math-constp (car a))))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
281 (null a))))) |
40785 | 282 |
283 | |
284 (defun calc-roll-down-stack (n &optional m) | |
285 (if (< n 0) | |
286 (calc-roll-up-stack (- n) m) | |
287 (if (or (= n 0) (> n (calc-stack-size))) (setq n (calc-stack-size))) | |
288 (or m (setq m 1)) | |
289 (and (> n 1) | |
290 (< m n) | |
291 (if (and calc-any-selections | |
292 (not calc-use-selections)) | |
293 (calc-roll-down-with-selections n m) | |
294 (calc-pop-push-list n | |
295 (append (calc-top-list m 1) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
296 (calc-top-list (- n m) (1+ m)))))))) |
40785 | 297 |
298 (defun calc-roll-up-stack (n &optional m) | |
299 (if (< n 0) | |
300 (calc-roll-down-stack (- n) m) | |
301 (if (or (= n 0) (> n (calc-stack-size))) (setq n (calc-stack-size))) | |
302 (or m (setq m 1)) | |
303 (and (> n 1) | |
304 (< m n) | |
305 (if (and calc-any-selections | |
306 (not calc-use-selections)) | |
307 (calc-roll-up-with-selections n m) | |
308 (calc-pop-push-list n | |
309 (append (calc-top-list (- n m) 1) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
310 (calc-top-list m (- n m -1)))))))) |
40785 | 311 |
312 | |
313 (defun calc-do-refresh () | |
314 (if calc-hyperbolic-flag | |
315 (progn | |
316 (setq calc-display-dirty t) | |
317 nil) | |
318 (calc-refresh) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
319 t)) |
40785 | 320 |
321 | |
322 (defun calc-record-list (vals &optional prefix) | |
323 (while vals | |
324 (or (eq (car vals) 'top-of-stack) | |
325 (progn | |
326 (calc-record (car vals) prefix) | |
327 (setq prefix "..."))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
328 (setq vals (cdr vals)))) |
40785 | 329 |
330 | |
331 (defun calc-last-args-stub (arg) | |
332 (interactive "p") | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
333 (require 'calc-ext) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
334 (calc-last-args arg)) |
40785 | 335 |
336 | |
337 (defun calc-power (arg) | |
338 (interactive "P") | |
339 (calc-slow-wrapper | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
340 (if (and (featurep 'calc-ext) |
40785 | 341 (calc-is-inverse)) |
342 (calc-binary-op "root" 'calcFunc-nroot arg nil nil) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
343 (calc-binary-op "^" 'calcFunc-pow arg nil nil '^)))) |
40785 | 344 |
345 (defun calc-mod (arg) | |
346 (interactive "P") | |
347 (calc-slow-wrapper | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
348 (calc-binary-op "%" 'calcFunc-mod arg nil nil '%))) |
40785 | 349 |
350 (defun calc-inv (arg) | |
351 (interactive "P") | |
352 (calc-slow-wrapper | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
353 (calc-unary-op "inv" 'calcFunc-inv arg))) |
40785 | 354 |
355 (defun calc-percent () | |
356 (interactive) | |
357 (calc-slow-wrapper | |
358 (calc-pop-push-record-list | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
359 1 "%" (list (list 'calcFunc-percent (calc-top-n 1)))))) |
40785 | 360 |
361 | |
362 (defun calc-over (n) | |
363 (interactive "P") | |
364 (if n | |
365 (calc-enter (- (prefix-numeric-value n))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
366 (calc-enter -2))) |
40785 | 367 |
368 | |
369 (defun calc-pop-above (n) | |
370 (interactive "P") | |
371 (if n | |
372 (calc-pop (- (prefix-numeric-value n))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
373 (calc-pop -2))) |
40785 | 374 |
375 (defun calc-roll-down (n) | |
376 (interactive "P") | |
377 (calc-wrapper | |
378 (let ((nn (prefix-numeric-value n))) | |
379 (cond ((null n) | |
380 (calc-roll-down-stack 2)) | |
381 ((> nn 0) | |
382 (calc-roll-down-stack nn)) | |
383 ((= nn 0) | |
384 (calc-pop-push-list (calc-stack-size) | |
385 (reverse | |
386 (calc-top-list (calc-stack-size))))) | |
387 (t | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
388 (calc-roll-down-stack (calc-stack-size) (- nn))))))) |
40785 | 389 |
390 (defun calc-roll-up (n) | |
391 (interactive "P") | |
392 (calc-wrapper | |
393 (let ((nn (prefix-numeric-value n))) | |
394 (cond ((null n) | |
395 (calc-roll-up-stack 3)) | |
396 ((> nn 0) | |
397 (calc-roll-up-stack nn)) | |
398 ((= nn 0) | |
399 (calc-pop-push-list (calc-stack-size) | |
400 (reverse | |
401 (calc-top-list (calc-stack-size))))) | |
402 (t | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
403 (calc-roll-up-stack (calc-stack-size) (- nn))))))) |
40785 | 404 |
405 | |
406 | |
407 | |
408 ;;; Other commands. | |
409 | |
410 (defun calc-num-prefix-name (n) | |
411 (cond ((eq n '-) "- ") | |
412 ((equal n '(4)) "C-u ") | |
413 ((consp n) (format "%d " (car n))) | |
414 ((integerp n) (format "%d " n)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
415 (t ""))) |
40785 | 416 |
417 (defun calc-missing-key (n) | |
418 "This is a placeholder for a command which needs to be loaded from calc-ext. | |
419 When this key is used, calc-ext (the Calculator extensions module) will be | |
420 loaded and the keystroke automatically re-typed." | |
421 (interactive "P") | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
422 (require 'calc-ext) |
40785 | 423 (if (keymapp (key-binding (char-to-string last-command-char))) |
424 (message "%s%c-" (calc-num-prefix-name n) last-command-char)) | |
425 (calc-unread-command) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
426 (setq prefix-arg n)) |
40785 | 427 |
428 (defun calc-shift-Y-prefix-help () | |
429 (interactive) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
430 (require 'calc-ext) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
431 (calc-do-prefix-help calc-Y-help-msgs "other" ?Y)) |
40785 | 432 |
433 | |
434 | |
435 | |
436 (defun calcDigit-letter () | |
437 (interactive) | |
438 (if (calc-minibuffer-contains "[-+]?\\(1[1-9]\\|[2-9][0-9]\\)#.*") | |
439 (progn | |
440 (setq last-command-char (upcase last-command-char)) | |
441 (calcDigit-key)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
442 (calcDigit-nondigit))) |
40785 | 443 |
444 | |
445 ;; A Lisp version of temp_minibuffer_message from minibuf.c. | |
446 (defun calc-temp-minibuffer-message (m) | |
447 (let ((savemax (point-max))) | |
448 (save-excursion | |
449 (goto-char (point-max)) | |
450 (insert m)) | |
451 (let ((okay nil)) | |
452 (unwind-protect | |
453 (progn | |
454 (sit-for 2) | |
455 (identity 1) ; this forces a call to QUIT; in bytecode.c. | |
456 (setq okay t)) | |
457 (progn | |
458 (delete-region savemax (point-max)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
459 (or okay (abort-recursive-edit))))))) |
40785 | 460 |
461 | |
462 (put 'math-with-extra-prec 'lisp-indent-hook 1) | |
463 | |
464 | |
465 ;;; Concatenate two vectors, or a vector and an object. [V O O] [Public] | |
466 (defun math-concat (v1 v2) | |
467 (if (stringp v1) | |
468 (concat v1 v2) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
469 (require 'calc-ext) |
40785 | 470 (if (and (or (math-objvecp v1) (math-known-scalarp v1)) |
471 (or (math-objvecp v2) (math-known-scalarp v2))) | |
472 (append (if (and (math-vectorp v1) | |
473 (or (math-matrixp v1) | |
474 (not (math-matrixp v2)))) | |
475 v1 | |
476 (list 'vec v1)) | |
477 (if (and (math-vectorp v2) | |
478 (or (math-matrixp v2) | |
479 (not (math-matrixp v1)))) | |
480 (cdr v2) | |
481 (list v2))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
482 (list '| v1 v2)))) |
40785 | 483 |
484 | |
485 ;;; True if A is zero. Works for un-normalized values. [P n] [Public] | |
486 (defun math-zerop (a) | |
487 (if (consp a) | |
488 (cond ((memq (car a) '(bigpos bigneg)) | |
489 (while (eq (car (setq a (cdr a))) 0)) | |
490 (null a)) | |
491 ((memq (car a) '(frac float polar mod)) | |
492 (math-zerop (nth 1 a))) | |
493 ((eq (car a) 'cplx) | |
494 (and (math-zerop (nth 1 a)) (math-zerop (nth 2 a)))) | |
495 ((eq (car a) 'hms) | |
496 (and (math-zerop (nth 1 a)) | |
497 (math-zerop (nth 2 a)) | |
498 (math-zerop (nth 3 a))))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
499 (eq a 0))) |
40785 | 500 |
501 | |
502 ;;; True if A is real and negative. [P n] [Public] | |
503 | |
504 (defun math-negp (a) | |
505 (if (consp a) | |
506 (cond ((eq (car a) 'bigpos) nil) | |
507 ((eq (car a) 'bigneg) (cdr a)) | |
508 ((memq (car a) '(float frac)) | |
509 (Math-integer-negp (nth 1 a))) | |
510 ((eq (car a) 'hms) | |
511 (if (math-zerop (nth 1 a)) | |
512 (if (math-zerop (nth 2 a)) | |
513 (math-negp (nth 3 a)) | |
514 (math-negp (nth 2 a))) | |
515 (math-negp (nth 1 a)))) | |
516 ((eq (car a) 'date) | |
517 (math-negp (nth 1 a))) | |
518 ((eq (car a) 'intv) | |
519 (or (math-negp (nth 3 a)) | |
520 (and (math-zerop (nth 3 a)) | |
521 (memq (nth 1 a) '(0 2))))) | |
522 ((equal a '(neg (var inf var-inf))) t)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
523 (< a 0))) |
40785 | 524 |
525 ;;; True if A is a negative number or an expression the starts with '-'. | |
526 (defun math-looks-negp (a) ; [P x] [Public] | |
527 (or (Math-negp a) | |
528 (eq (car-safe a) 'neg) | |
529 (and (memq (car-safe a) '(* /)) | |
530 (or (math-looks-negp (nth 1 a)) | |
531 (math-looks-negp (nth 2 a)))) | |
532 (and (eq (car-safe a) '-) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
533 (math-looks-negp (nth 1 a))))) |
40785 | 534 |
535 | |
536 ;;; True if A is real and positive. [P n] [Public] | |
537 (defun math-posp (a) | |
538 (if (consp a) | |
539 (cond ((eq (car a) 'bigpos) (cdr a)) | |
540 ((eq (car a) 'bigneg) nil) | |
541 ((memq (car a) '(float frac)) | |
542 (Math-integer-posp (nth 1 a))) | |
543 ((eq (car a) 'hms) | |
544 (if (math-zerop (nth 1 a)) | |
545 (if (math-zerop (nth 2 a)) | |
546 (math-posp (nth 3 a)) | |
547 (math-posp (nth 2 a))) | |
548 (math-posp (nth 1 a)))) | |
549 ((eq (car a) 'date) | |
550 (math-posp (nth 1 a))) | |
551 ((eq (car a) 'mod) | |
552 (not (math-zerop (nth 1 a)))) | |
553 ((eq (car a) 'intv) | |
554 (or (math-posp (nth 2 a)) | |
555 (and (math-zerop (nth 2 a)) | |
556 (memq (nth 1 a) '(0 1))))) | |
557 ((equal a '(var inf var-inf)) t)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
558 (> a 0))) |
40785 | 559 |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
560 (defalias 'math-fixnump 'integerp) |
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
561 (defalias 'math-fixnatnump 'natnump) |
40785 | 562 |
563 | |
564 ;;; True if A is an even integer. [P R R] [Public] | |
565 (defun math-evenp (a) | |
566 (if (consp a) | |
567 (and (memq (car a) '(bigpos bigneg)) | |
568 (= (% (nth 1 a) 2) 0)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
569 (= (% a 2) 0))) |
40785 | 570 |
571 ;;; Compute A / 2, for small or big integer A. [I i] | |
572 ;;; If A is negative, type of truncation is undefined. | |
573 (defun math-div2 (a) | |
574 (if (consp a) | |
575 (if (cdr a) | |
576 (math-normalize (cons (car a) (math-div2-bignum (cdr a)))) | |
577 0) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
578 (/ a 2))) |
40785 | 579 |
580 (defun math-div2-bignum (a) ; [l l] | |
581 (if (cdr a) | |
582 (cons (+ (/ (car a) 2) (* (% (nth 1 a) 2) 500)) | |
583 (math-div2-bignum (cdr a))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
584 (list (/ (car a) 2)))) |
40785 | 585 |
586 | |
587 ;;; Reject an argument to a calculator function. [Public] | |
588 (defun math-reject-arg (&optional a p option) | |
589 (if option | |
590 (calc-record-why option p a) | |
591 (if p | |
592 (calc-record-why p a))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
593 (signal 'wrong-type-argument (and a (if p (list p a) (list a))))) |
40785 | 594 |
595 | |
596 ;;; Coerce A to be an integer (by truncation toward zero). [I N] [Public] | |
58480
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
597 |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
598 ;; The variable math-trunc-prec is local to math-trunc, but used by |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
599 ;; math-trunc-fancy in calc-arith.el, which is called by math-trunc. |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
600 |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
601 (defun math-trunc (a &optional math-trunc-prec) |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
602 (cond (math-trunc-prec |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
603 (require 'calc-ext) |
58480
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
604 (math-trunc-special a math-trunc-prec)) |
40785 | 605 ((Math-integerp a) a) |
606 ((Math-looks-negp a) | |
607 (math-neg (math-trunc (math-neg a)))) | |
608 ((eq (car a) 'float) | |
609 (math-scale-int (nth 1 a) (nth 2 a))) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
610 (t (require 'calc-ext) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
611 (math-trunc-fancy a)))) |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
612 (defalias 'calcFunc-trunc 'math-trunc) |
40785 | 613 |
614 ;;; Coerce A to be an integer (by truncation toward minus infinity). [I N] | |
58480
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
615 |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
616 ;; The variable math-floor-prec is local to math-floor, but used by |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
617 ;; math-floor-fancy in calc-arith.el, which is called by math-floor. |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
618 |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
619 (defun math-floor (a &optional math-floor-prec) ; [Public] |
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
620 (cond (math-floor-prec |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
621 (require 'calc-ext) |
58480
d11199c971ec
(math-trunc): Replace variable prec by math-trunc-prec.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57711
diff
changeset
|
622 (math-floor-special a math-floor-prec)) |
40785 | 623 ((Math-integerp a) a) |
624 ((Math-messy-integerp a) (math-trunc a)) | |
625 ((Math-realp a) | |
626 (if (Math-negp a) | |
627 (math-add (math-trunc a) -1) | |
628 (math-trunc a))) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
629 (t (require 'calc-ext) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
630 (math-floor-fancy a)))) |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
631 (defalias 'calcFunc-floor 'math-floor) |
40785 | 632 |
633 | |
634 (defun math-imod (a b) ; [I I I] [Public] | |
635 (if (and (not (consp a)) (not (consp b))) | |
636 (if (= b 0) | |
637 (math-reject-arg a "*Division by zero") | |
638 (% a b)) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
639 (cdr (math-idivmod a b)))) |
40785 | 640 |
641 | |
642 (defun calcFunc-inv (m) | |
643 (if (Math-vectorp m) | |
644 (progn | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
645 (require 'calc-ext) |
40785 | 646 (if (math-square-matrixp m) |
647 (or (math-with-extra-prec 2 (math-matrix-inv-raw m)) | |
648 (math-reject-arg m "*Singular matrix")) | |
649 (math-reject-arg m 'square-matrixp))) | |
66480
feb65aa82eeb
(calcFunc-inv): Check for symbolic matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
650 (if (and |
feb65aa82eeb
(calcFunc-inv): Check for symbolic matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
651 (require 'calc-arith) |
feb65aa82eeb
(calcFunc-inv): Check for symbolic matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
652 (math-known-matrixp m)) |
feb65aa82eeb
(calcFunc-inv): Check for symbolic matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
653 (math-pow m -1) |
feb65aa82eeb
(calcFunc-inv): Check for symbolic matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
654 (math-div 1 m)))) |
40785 | 655 |
656 (defun math-do-working (msg arg) | |
40998
ee9c2872370b
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
657 (or executing-kbd-macro |
40785 | 658 (progn |
659 (calc-set-command-flag 'clear-message) | |
660 (if math-working-step | |
661 (if math-working-step-2 | |
662 (setq msg (format "[%d/%d] %s" | |
663 math-working-step math-working-step-2 msg)) | |
664 (setq msg (format "[%d] %s" math-working-step msg)))) | |
665 (message "Working... %s = %s" msg | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
666 (math-showing-full-precision (math-format-number arg)))))) |
40785 | 667 |
668 | |
669 ;;; Compute A modulo B, defined in terms of truncation toward minus infinity. | |
670 (defun math-mod (a b) ; [R R R] [Public] | |
671 (cond ((and (Math-zerop a) (not (eq (car-safe a) 'mod))) a) | |
672 ((Math-zerop b) | |
673 (math-reject-arg a "*Division by zero")) | |
674 ((and (Math-natnump a) (Math-natnump b)) | |
675 (math-imod a b)) | |
676 ((and (Math-anglep a) (Math-anglep b)) | |
677 (math-sub a (math-mul (math-floor (math-div a b)) b))) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
678 (t (require 'calc-ext) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
679 (math-mod-fancy a b)))) |
40785 | 680 |
681 | |
682 | |
683 ;;; General exponentiation. | |
684 | |
685 (defun math-pow (a b) ; [O O N] [Public] | |
686 (cond ((equal b '(var nan var-nan)) | |
687 b) | |
688 ((Math-zerop a) | |
689 (if (and (Math-scalarp b) (Math-posp b)) | |
690 (if (math-floatp b) (math-float a) a) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
691 (require 'calc-ext) |
40785 | 692 (math-pow-of-zero a b))) |
693 ((or (eq a 1) (eq b 1)) a) | |
694 ((or (equal a '(float 1 0)) (equal b '(float 1 0))) a) | |
695 ((Math-zerop b) | |
696 (if (Math-scalarp a) | |
697 (if (or (math-floatp a) (math-floatp b)) | |
698 '(float 1 0) 1) | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
699 (require 'calc-ext) |
40785 | 700 (math-pow-zero a b))) |
701 ((and (Math-integerp b) (or (Math-numberp a) (Math-vectorp a))) | |
702 (if (and (equal a '(float 1 1)) (integerp b)) | |
703 (math-make-float 1 b) | |
704 (math-with-extra-prec 2 | |
705 (math-ipow a b)))) | |
706 (t | |
58613
3eb7a394510d
(calc-do-handle-whys, calc-last-args-stub, calc-missing-key)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58543
diff
changeset
|
707 (require 'calc-ext) |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
708 (math-pow-fancy a b)))) |
40785 | 709 |
710 (defun math-ipow (a n) ; [O O I] [Public] | |
711 (cond ((Math-integer-negp n) | |
712 (math-ipow (math-div 1 a) (Math-integer-neg n))) | |
713 ((not (consp n)) | |
714 (if (and (Math-ratp a) (> n 20)) | |
715 (math-iipow-show a n) | |
716 (math-iipow a n))) | |
717 ((math-evenp n) | |
718 (math-ipow (math-mul a a) (math-div2 n))) | |
719 (t | |
720 (math-mul a (math-ipow (math-mul a a) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
721 (math-div2 (math-add n -1))))))) |
40785 | 722 |
723 (defun math-iipow (a n) ; [O O S] | |
724 (cond ((= n 0) 1) | |
725 ((= n 1) a) | |
726 ((= (% n 2) 0) (math-iipow (math-mul a a) (/ n 2))) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
727 (t (math-mul a (math-iipow (math-mul a a) (/ n 2)))))) |
40785 | 728 |
729 (defun math-iipow-show (a n) ; [O O S] | |
730 (math-working "pow" a) | |
731 (let ((val (cond | |
732 ((= n 0) 1) | |
733 ((= n 1) a) | |
734 ((= (% n 2) 0) (math-iipow-show (math-mul a a) (/ n 2))) | |
735 (t (math-mul a (math-iipow-show (math-mul a a) (/ n 2))))))) | |
736 (math-working "pow" val) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
737 val)) |
40785 | 738 |
739 | |
740 (defun math-read-radix-digit (dig) ; [D S; Z S] | |
741 (if (> dig ?9) | |
742 (if (< dig ?A) | |
743 nil | |
744 (- dig 55)) | |
745 (if (>= dig ?0) | |
746 (- dig ?0) | |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
747 nil))) |
40785 | 748 |
749 | |
750 ;;; Bug reporting | |
751 | |
41377
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
752 (defun report-calc-bug () |
40785 | 753 "Report a bug in Calc, the GNU Emacs calculator. |
754 Prompts for bug subject. Leaves you in a mail buffer." | |
41377
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
755 (interactive) |
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
756 (let ((reporter-prompt-for-summary-p t)) |
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
757 (reporter-submit-bug-report calc-bug-address "Calc" '(calc-version) |
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
758 nil nil |
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
759 "Please describe exactly what actions triggered the bug and the |
41363
f17cae9ea728
(report-calc-bug): Use reporter.el.
Colin Walters <walters@gnu.org>
parents:
41359
diff
changeset
|
760 precise symptoms of the bug. If possible, include a backtrace by |
f17cae9ea728
(report-calc-bug): Use reporter.el.
Colin Walters <walters@gnu.org>
parents:
41359
diff
changeset
|
761 doing 'M-x toggle-debug-on-error', then reproducing the bug. |
41377
be3e9c2f0159
(report-calc-bug): Use `reporter-prompt-for-summary-p'.
Colin Walters <walters@gnu.org>
parents:
41363
diff
changeset
|
762 " ))) |
41267
e9718841a5b1
(math-fixnump, math-fixnatnump, calcFunc-trunc)
Colin Walters <walters@gnu.org>
parents:
41045
diff
changeset
|
763 (defalias 'calc-report-bug 'report-calc-bug) |
40785 | 764 |
58664
f23c98cc77a1
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58613
diff
changeset
|
765 (provide 'calc-misc) |
f23c98cc77a1
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58613
diff
changeset
|
766 |
52401 | 767 ;;; arch-tag: 7984d9d0-62e5-41dc-afb8-e904b975f250 |
41045
3491bfbd825e
(math-fixnump, math-fixnatnump, calcFunc-trunc, calcFunc-floor,
Colin Walters <walters@gnu.org>
parents:
40998
diff
changeset
|
768 ;;; calc-misc.el ends here |