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