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