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