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