Mercurial > emacs
annotate lisp/calc/calc.el @ 47640:d5e4a276998c
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 27 Sep 2002 00:47:25 +0000 |
parents | 663c306c80c6 |
children | 172cf7391545 |
rev | line source |
---|---|
41283
1c09d8ddd155
(toplevel): Add comment and version header.
Colin Walters <walters@gnu.org>
parents:
41270
diff
changeset
|
1 ;;; calc.el --- the GNU Emacs calculator |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
43185
e38061462de6
(calcDigit-key): Use minibuffer-prompt-end instead of point-min.
Andreas Schwab <schwab@suse.de>
parents:
42205
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002 Free Software Foundation, Inc. |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
4 |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
6 ;; Maintainer: Colin Walters <walters@debian.org> |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
7 ;; Keywords: convenience, extensions |
41283
1c09d8ddd155
(toplevel): Add comment and version header.
Colin Walters <walters@gnu.org>
parents:
41270
diff
changeset
|
8 ;; Version: 2.02g |
40785 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
14 ;; accepts responsibility to anyone for the consequences of using it | |
15 ;; or for whether it serves any particular purpose or works at all, | |
16 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
17 ;; License for full details. | |
18 | |
19 ;; Everyone is granted permission to copy, modify and redistribute | |
20 ;; GNU Emacs, but only under the conditions described in the | |
21 ;; GNU Emacs General Public License. A copy of this license is | |
22 ;; supposed to have been given to you along with GNU Emacs so you | |
23 ;; can know your rights and responsibilities. It should be in a | |
24 ;; file named COPYING. Among other things, the copyright notice | |
25 ;; and this notice must be preserved on all copies. | |
26 | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
27 ;;; Commentary: |
40785 | 28 |
41455
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
29 ;; Calc is split into many files. This file is the main entry point. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
30 ;; This file includes autoload commands for various other basic Calc |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
31 ;; facilities. The more advanced features are based in calc-ext, which |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
32 ;; in turn contains autoloads for the rest of the Calc files. This |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
33 ;; odd set of interactions is designed to make Calc's loading time |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
34 ;; be as short as possible when only simple calculations are needed. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
35 |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
36 ;; Original author's address: |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
37 ;; Dave Gillespie, daveg@synaptics.com, uunet!synaptx!daveg. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
38 ;; Synaptics, Inc., 2698 Orchard Parkway, San Jose, CA 95134. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
39 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
40 ;; The old address daveg@csvax.cs.caltech.edu will continue to |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
41 ;; work for the foreseeable future. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
42 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
43 ;; Bug reports and suggestions are always welcome! (Type M-x |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
44 ;; report-calc-bug to send them). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
45 |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
46 ;; All functions, macros, and Lisp variables defined here begin with one |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
47 ;; of the prefixes "math", "Math", or "calc", with the exceptions of |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
48 ;; "full-calc", "full-calc-keypad", "another-calc", "quick-calc", |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
49 ;; "report-calc-bug", and "defmath". User-accessible variables begin |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
50 ;; with "var-". |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
51 |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
52 ;;; TODO: |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
53 |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
54 ;; Fix rewrite mechanism to do less gratuitous rearrangement of terms. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
55 ;; Implement a pattern-based "refers" predicate. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
56 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
57 ;; Make it possible to Undo a selection command. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
58 ;; Figure out how to allow selecting rows of matrices. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
59 ;; If cursor was in selection before, move it after j n, j p, j L, etc. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
60 ;; Consider reimplementing calc-delete-selection using rewrites. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
61 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
62 ;; Implement line-breaking in non-flat compositions (is this desirable?). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
63 ;; Implement matrix formatting with multi-line components. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
64 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
65 ;; Have "Z R" define a user command based on a set of rewrite rules. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
66 ;; Support "incf" and "decf" in defmath definitions. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
67 ;; Have defmath generate calls to calc-binary-op or calc-unary-op. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
68 ;; Make some way to define algebraic functions using keyboard macros. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
69 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
70 ;; Allow calc-word-size=0 => Common Lisp-style signed bitwise arithmetic. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
71 ;; Consider digamma function (and thus arb. prec. Euler's gamma constant). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
72 ;; May as well make continued-fractions stuff available to the user. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
73 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
74 ;; How about matrix eigenvalues, SVD, pseudo-inverse, etc.? |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
75 ;; Should cache matrix inverses as well as decompositions. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
76 ;; If dividing by a non-square matrix, use least-squares automatically. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
77 ;; Consider supporting matrix exponentials. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
78 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
79 ;; Have ninteg detect and work around singularities at the endpoints. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
80 ;; Use an adaptive subdivision algorithm for ninteg. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
81 ;; Provide nsum and nprod to go along with ninteg. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
82 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
83 ;; Handle TeX-mode parsing of \matrix{ ... } where ... contains braces. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
84 ;; Support AmS-TeX's \{d,t,}frac, \{d,t,}binom notations. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
85 ;; Format and parse sums and products in Eqn and Math modes. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
86 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
87 ;; Get math-read-big-expr to read sums, products, etc. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
88 ;; Change calc-grab-region to use math-read-big-expr. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
89 ;; Have a way to define functions using := in Embedded Mode. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
90 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
91 ;; Support polar plotting with GNUPLOT. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
92 ;; Make a calc-graph-histogram function. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
93 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
94 ;; Replace hokey formulas for complex functions with formulas designed |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
95 ;; to minimize roundoff while maintaining the proper branch cuts. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
96 ;; Test accuracy of advanced math functions over whole complex plane. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
97 ;; Extend Bessel functions to provide arbitrary precision. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
98 ;; Extend advanced math functions to handle error forms and intervals. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
99 ;; Provide a better implementation for math-sin-cos-raw. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
100 ;; Provide a better implementation for math-hypot. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
101 ;; Provide a better implementation for math-make-frac. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
102 ;; Provide a better implementation for calcFunc-prfac. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
103 ;; Provide a better implementation for calcFunc-factor. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
104 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
105 ;; Provide more examples in the tutorial section of the manual. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
106 ;; Cover in the tutorial: simplification modes, declarations, |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
107 ;; bitwise stuff, selections, matrix mapping, financial functions. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
108 ;; Provide more Lisp programming examples in the manual. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
109 ;; Finish the Internals section of the manual (and bring it up to date). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
110 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
111 ;; Tim suggests adding spreadsheet-like features. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
112 ;; Implement language modes for Gnuplot, Lisp, Ada, APL, ...? |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
113 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
114 ;; For atan series, if x > tan(pi/12) (about 0.268) reduce using the identity |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
115 ;; atan(x) = atan((x * sqrt(3) - 1) / (sqrt(3) + x)) + pi/6. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
116 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
117 ;; A better integration algorithm: |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
118 ;; Use breadth-first instead of depth-first search, as follows: |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
119 ;; The integral cache allows unfinished integrals in symbolic notation |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
120 ;; on the righthand side. An entry with no unfinished integrals on the |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
121 ;; RHS is "complete"; references to it elsewhere are replaced by the |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
122 ;; integrated value. More than one cache entry for the same integral |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
123 ;; may exist, though if one becomes complete, the others may be deleted. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
124 ;; The integrator works by using every applicable rule (such as |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
125 ;; substitution, parts, linearity, etc.) to generate possible righthand |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
126 ;; sides, all of which are entered into the cache. Now, as long as the |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
127 ;; target integral is not complete (and the time limit has not run out) |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
128 ;; choose an incomplete integral from the cache and, for every integral |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
129 ;; appearing in its RHS's, add those integrals to the cache using the |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
130 ;; same substitition, parts, etc. rules. The cache should be organized |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
131 ;; as a priority queue, choosing the "simplest" incomplete integral at |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
132 ;; each step, or choosing randomly among equally simple integrals. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
133 ;; Simplicity equals small size, and few steps removed from the original |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
134 ;; target integral. Note that when the integrator finishes, incomplete |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
135 ;; integrals can be left in the cache, so the algorithm can start where |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
136 ;; it left off if another similar integral is later requested. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
137 ;; Breadth-first search would avoid the nagging problem of, e.g., whether |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
138 ;; to use parts or substitution first, and which decomposition is best. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
139 ;; All are tried, and any path that diverges will quickly be put on the |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
140 ;; back burner by the priority queue. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
141 ;; Note: Probably a good idea to call math-simplify-extended before |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
142 ;; measuring a formula's simplicity. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
143 |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
144 ;; From: "Robert J. Chassell" <bob@rattlesnake.com> |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
145 ;; Subject: Re: fix for `Cannot open load file: calc-alg-3' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
146 ;; To: walters@debian.org |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
147 ;; Date: Sat, 24 Nov 2001 21:44:21 +0000 (UTC) |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
148 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
149 ;; Could you add logistic curve fitting to the current list? |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
150 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
151 ;; (I guess the key binding for a logistic curve would have to be `s' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
152 ;; since a logistic curve is an `s' curve; both `l' and `L' are already |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
153 ;; taken for logarithms.) |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
154 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
155 ;; Here is the current list for curve fitting; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
156 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
157 ;; `1' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
158 ;; Linear or multilinear. a + b x + c y + d z. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
159 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
160 ;; `2-9' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
161 ;; Polynomials. a + b x + c x^2 + d x^3. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
162 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
163 ;; `e' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
164 ;; Exponential. a exp(b x) exp(c y). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
165 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
166 ;; `E' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
167 ;; Base-10 exponential. a 10^(b x) 10^(c y). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
168 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
169 ;; `x' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
170 ;; Exponential (alternate notation). exp(a + b x + c y). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
171 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
172 ;; `X' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
173 ;; Base-10 exponential (alternate). 10^(a + b x + c y). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
174 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
175 ;; `l' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
176 ;; Logarithmic. a + b ln(x) + c ln(y). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
177 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
178 ;; `L' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
179 ;; Base-10 logarithmic. a + b log10(x) + c log10(y). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
180 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
181 ;; `^' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
182 ;; General exponential. a b^x c^y. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
183 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
184 ;; `p' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
185 ;; Power law. a x^b y^c. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
186 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
187 ;; `q' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
188 ;; Quadratic. a + b (x-c)^2 + d (x-e)^2. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
189 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
190 ;; `g' |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
191 ;; Gaussian. (a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2). |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
192 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
193 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
194 ;; Logistic curves are used a great deal in ecology, and in predicting |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
195 ;; human actions, such as use of different kinds of energy in a country |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
196 ;; (wood, coal, oil, natural gas, etc.) or the number of scientific |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
197 ;; papers a person publishes, or the number of movies made. |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
198 ;; |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
199 ;; (The less information on which to base the curve, the higher the error |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
200 ;; rate. Theodore Modis ran some Monte Carlo simulations and produced |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
201 ;; what may be useful set of confidence levels for different amounts of |
ede347046135
(Commentary): Cleanup, and add logistic curve fitting suggestion from
Colin Walters <walters@gnu.org>
parents:
41283
diff
changeset
|
202 ;; initial information.) |
40785 | 203 |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
204 ;;; Code: |
40785 | 205 |
206 (provide 'calc) | |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
207 (require 'calc-macs) |
40785 | 208 |
209 ;;; The "###autoload" comment will be used by Emacs version 19 for | |
210 ;;; maintaining the loaddefs.el file automatically. | |
211 | |
212 ;;;###autoload | |
213 (defvar calc-info-filename "calc.info" | |
214 "*File name in which to look for the Calculator's Info documentation.") | |
215 | |
216 ;;;###autoload | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
217 (defvar calc-settings-file user-init-file |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
218 "*File in which to record permanent settings; default is `user-init-file'.") |
40785 | 219 |
220 ;;;###autoload | |
221 (defvar calc-autoload-directory nil | |
222 "Name of directory from which additional \".elc\" files for Calc should be | |
223 loaded. Should include a trailing \"/\". | |
224 If nil, use original installation directory. | |
225 This can safely be nil as long as the Calc files are on the load-path.") | |
226 | |
227 ;;;###autoload | |
228 (defvar calc-gnuplot-name "gnuplot" | |
229 "*Name of GNUPLOT program, for calc-graph features.") | |
230 | |
231 ;;;###autoload | |
232 (defvar calc-gnuplot-plot-command nil | |
233 "*Name of command for displaying GNUPLOT output; %s = file name to print.") | |
234 | |
235 ;;;###autoload | |
236 (defvar calc-gnuplot-print-command "lp %s" | |
237 "*Name of command for printing GNUPLOT output; %s = file name to print.") | |
238 | |
239 ;; Address of the author of Calc, for use by report-calc-bug. | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
240 (defvar calc-bug-address "walters@debian.org") |
40785 | 241 |
42205 | 242 ;; If t, scan keymaps to find all DEL-like keys. |
243 ;; if nil, only DEL itself is mapped to calc-pop. | |
40785 | 244 (defvar calc-scan-for-dels t) |
245 | |
246 (defvar calc-extensions-loaded nil) | |
247 | |
248 ;; Calculator stack. | |
249 ;; Entries are 3-lists: Formula, Height (in lines), Selection (or nil). | |
250 (defvar calc-stack '((top-of-stack 1 nil))) | |
251 | |
45578
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
252 (defvar calc-show-banner t |
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
253 "*If non-nil, show a friendly greeting above the stack.") |
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
254 |
40785 | 255 ;; Index into calc-stack of "top" of stack. |
256 ;; This is 1 unless calc-truncate-stack has been used. | |
257 ;;(defvar calc-stack-top 1) | |
258 | |
42205 | 259 ;; If non-nil, load the calc-ext module automatically when calc is loaded. |
40785 | 260 ;;(defvar calc-always-load-extensions nil) |
261 | |
42205 | 262 ;; If non-nil, display line numbers in Calculator stack. |
40785 | 263 ;;(defvar calc-line-numbering t) |
264 | |
42205 | 265 ;; If non-nil, break long values across multiple lines in Calculator stack. |
40785 | 266 ;;(defvar calc-line-breaking t) |
267 | |
42205 | 268 ;; If nil, stack display is left-justified. |
40785 | 269 ;; If 'right, stack display is right-justified. |
270 ;; If 'center, stack display is centered." | |
271 ;;(defvar calc-display-just nil) | |
272 | |
273 ;; Horizontal origin of displayed stack entries. | |
274 ;; In left-justified mode, this is effectively indentation. (Default 0). | |
275 ;; In right-justified mode, this is effectively window width. | |
276 ;; In centered mode, center of stack entry is placed here. | |
277 ;;(defvar calc-display-origin nil) | |
278 | |
279 ;; Radix for entry and display of numbers in calc-mode, 2-36. | |
280 ;;(defvar calc-number-radix 10) | |
281 | |
42205 | 282 ;; If non-nil, leading zeros are provided to pad integers to calc-word-size. |
40785 | 283 ;;(defvar calc-leading-zeros nil) |
284 | |
42205 | 285 ;; If non-nil, group digits in large displayed integers by inserting spaces. |
40785 | 286 ;; If an integer, group that many digits at a time. |
287 ;; If 't', use 4 for binary and hex, 3 otherwise. | |
288 ;;(defvar calc-group-digits nil) | |
289 | |
290 ;; The character (in the form of a string) to be used for grouping digits. | |
291 ;; This is used only when calc-group-digits mode is on. | |
292 ;;(defvar calc-group-char ",") | |
293 | |
294 ;; The character (in the form of a string) to be used as a decimal point. | |
295 ;;(defvar calc-point-char ".") | |
296 | |
297 ;; Format of displayed fractions; a string of one or two of ":" or "/". | |
298 ;;(defvar calc-frac-format '(":" nil)) | |
299 | |
42205 | 300 ;; If non-nil, prefer fractional over floating-point results. |
40785 | 301 ;;(defvar calc-prefer-frac nil) |
302 | |
303 ;; Format of displayed hours-minutes-seconds angles, a format string. | |
304 ;; String must contain three %s marks for hours, minutes, seconds respectively. | |
305 ;;(defvar calc-hms-format "%s@ %s' %s\"") | |
306 | |
307 ;; Format of displayed date forms. | |
308 ;;(defvar calc-date-format '((H ":" mm ":" SS pp " ") Www " " Mmm " " D ", " YYYY)) | |
309 | |
310 ;; Format to use for display of floating-point numbers in calc-mode. | |
311 ;; Must be a list of one of the following forms: | |
312 ;; (float 0) Floating point format, display full precision. | |
313 ;; (float N) N > 0: Floating point format, at most N significant figures. | |
314 ;; (float -N) -N < 0: Floating point format, calc-internal-prec - N figs. | |
315 ;; (fix N) N >= 0: Fixed point format, N places after decimal point. | |
316 ;; (sci 0) Scientific notation, full precision. | |
317 ;; (sci N) N > 0: Scientific notation, N significant figures. | |
318 ;; (sci -N) -N < 0: Scientific notation, calc-internal-prec - N figs. | |
319 ;; (eng 0) Engineering notation, full precision. | |
320 ;; (eng N) N > 0: Engineering notation, N significant figures. | |
321 ;; (eng -N) -N < 0: Engineering notation, calc-internal-prec - N figs. | |
322 ;;(defvar calc-float-format '(float 0)) | |
323 | |
324 ;; Format to use when full precision must be displayed. | |
325 ;;(defvar calc-full-float-format '(float 0)) | |
326 | |
327 ;; Format to use for display of complex numbers in calc-mode. Must be one of: | |
328 ;; nil Use (x, y) form. | |
329 ;; i Use x + yi form. | |
330 ;; j Use x + yj form. | |
331 ;;(defvar calc-complex-format nil) | |
332 | |
333 ;; Preferred form, either 'cplx or 'polar, for complex numbers. | |
334 ;;(defvar calc-complex-mode 'cplx) | |
335 | |
42205 | 336 ;; If nil, 1 / 0 is left unsimplified. |
40785 | 337 ;; If 0, 1 / 0 is changed to inf (zeros are considered positive). |
338 ;; Otherwise, 1 / 0 is changed to uinf (undirected infinity). | |
339 ;;(defvar calc-infinite-mode nil) | |
340 | |
42205 | 341 ;; If non-nil, display vectors of byte-sized integers as strings. |
40785 | 342 ;;(defvar calc-display-strings nil) |
343 | |
42205 | 344 ;; If nil, vector elements are left-justified. |
40785 | 345 ;; If 'right, vector elements are right-justified. |
346 ;; If 'center, vector elements are centered." | |
347 ;;(defvar calc-matrix-just 'center) | |
348 | |
42205 | 349 ;; If non-nil, display vectors one element per line. |
40785 | 350 ;;(defvar calc-break-vectors nil) |
351 | |
42205 | 352 ;; If non-nil, display long vectors in full. If nil, use abbreviated form. |
40785 | 353 ;;(defvar calc-full-vectors t) |
354 | |
42205 | 355 ;; If non-nil, display long vectors in full in the trail. |
40785 | 356 ;;(defvar calc-full-trail-vectors t) |
357 | |
42205 | 358 ;; If non-nil, separate elements of displayed vectors with this string. |
40785 | 359 ;;(defvar calc-vector-commas ",") |
360 | |
42205 | 361 ;; If non-nil, surround displayed vectors with these characters. |
40785 | 362 ;;(defvar calc-vector-brackets "[]") |
363 | |
364 ;; A list of code-letter symbols that control "big" matrix display. | |
365 ;; If 'R is present, display inner brackets for matrices. | |
366 ;; If 'O is present, display outer brackets for matrices (above/below). | |
367 ;; If 'C is present, display outer brackets for matrices (centered). | |
368 ;;(defvar calc-matrix-brackets '(R O)) | |
369 | |
370 ;; Language or format for entry and display of stack values. Must be one of: | |
371 ;; nil Use standard Calc notation. | |
372 ;; flat Use standard Calc notation, one-line format. | |
373 ;; big Display formulas in 2-d notation (enter w/std notation). | |
374 ;; unform Use unformatted display: add(a, mul(b,c)). | |
375 ;; c Use C language notation. | |
376 ;; pascal Use Pascal language notation. | |
377 ;; fortran Use Fortran language notation. | |
378 ;; tex Use TeX notation. | |
379 ;; eqn Use eqn notation. | |
380 ;; math Use Mathematica(tm) notation. | |
381 ;; maple Use Maple notation. | |
382 ;;(defvar calc-language nil) | |
383 | |
384 ;; Numeric prefix argument for the command that set calc-language. | |
385 ;;(defvar calc-language-option nil) | |
386 | |
387 ;; Open-parenthesis string for function call notation. | |
388 ;;(defvar calc-function-open "(") | |
389 | |
390 ;; Close-parenthesis string for function call notation. | |
391 ;;(defvar calc-function-close ")") | |
392 | |
393 ;; Function through which to pass strings after formatting. | |
394 ;;(defvar calc-language-output-filter nil) | |
395 | |
396 ;; Function through which to pass strings before parsing. | |
397 ;;(defvar calc-language-input-filter nil) | |
398 | |
399 ;; Formatting function used for non-decimal numbers. | |
400 ;;(defvar calc-radix-formatter nil) | |
401 | |
402 ;; Label to display at left of formula. | |
403 ;;(defvar calc-left-label "") | |
404 | |
405 ;; Label to display at right of formula. | |
406 ;;(defvar calc-right-label "") | |
407 | |
408 ;; Minimum number of bits per word, if any, for binary operations in calc-mode. | |
409 ;;(defvar calc-word-size 32) | |
410 | |
411 ;; Most recently used value of M in a modulo form. | |
412 ;;(defvar calc-previous-modulo nil) | |
413 | |
414 ;; Type of simplification applied to results. | |
415 ;; If 'none, results are not simplified when pushed on the stack. | |
416 ;; If 'num, functions are simplified only when args are constant. | |
42205 | 417 ;; If nil, only fast simplifications are applied. |
40785 | 418 ;; If 'binary, math-clip is applied if appropriate. |
419 ;; If 'alg, math-simplify is applied. | |
420 ;; If 'ext, math-simplify-extended is applied. | |
421 ;; If 'units, math-simplify-units is applied. | |
422 ;;(defvar calc-simplify-mode nil) | |
423 | |
42205 | 424 ;; If non-nil, recompute evalto's automatically when necessary. |
40785 | 425 ;;(defvar calc-auto-recompute t) |
426 | |
42205 | 427 ;; If non-nil, display shows unformatted Lisp exprs. (For debugging) |
40785 | 428 ;;(defvar calc-display-raw nil) |
429 | |
430 ;; Number of digits of internal precision for calc-mode calculations. | |
431 ;;(defvar calc-internal-prec 12) | |
432 | |
42205 | 433 ;; If non-nil, next operation is Inverse. |
40785 | 434 ;;(defvar calc-inverse-flag nil) |
435 | |
42205 | 436 ;; If non-nil, next operation is Hyperbolic. |
40785 | 437 ;;(defvar calc-hyperbolic-flag nil) |
438 | |
42205 | 439 ;; If non-nil, next operation should not remove its arguments from stack. |
40785 | 440 ;;(defvar calc-keep-args-flag nil) |
441 | |
442 ;; If deg, angles are in degrees; if rad, angles are in radians. | |
443 ;; If hms, angles are in degrees-minutes-seconds. | |
444 ;;(defvar calc-angle-mode 'deg) | |
445 | |
42205 | 446 ;; If non-nil, numeric entry accepts whole algebraic expressions. |
447 ;; If nil, algebraic expressions must be preceded by "'". | |
40785 | 448 ;;(defvar calc-algebraic-mode nil) |
449 | |
450 ;; Like calc-algebraic-mode except only affects ( and [ keys. | |
451 ;;(defvar calc-incomplete-algebraic-mode nil) | |
452 | |
42205 | 453 ;; If non-nil, inexact numeric computations like sqrt(2) are postponed. |
454 ;; If nil, computations on numbers always yield numbers where possible. | |
40785 | 455 ;;(defvar calc-symbolic-mode nil) |
456 | |
457 ;; If 'matrix, variables are assumed to be matrix-valued. | |
458 ;; If a number, variables are assumed to be NxN matrices. | |
459 ;; If 'scalar, variables are assumed to be scalar-valued. | |
42205 | 460 ;; If nil, symbolic math routines make no assumptions about variables. |
40785 | 461 ;;(defvar calc-matrix-mode nil) |
462 | |
42205 | 463 ;; If non-nil, shifted letter keys are prefix keys rather than normal meanings. |
40785 | 464 ;;(defvar calc-shift-prefix nil) |
465 | |
466 ;; Initial height of Calculator window. | |
467 ;;(defvar calc-window-height 7) | |
468 | |
42205 | 469 ;; If non-nil, M-x calc creates a window to display Calculator trail. |
40785 | 470 ;;(defvar calc-display-trail t) |
471 | |
42205 | 472 ;; If non-nil, selected sub-formulas are shown by obscuring rest of formula. |
473 ;; If nil, selected sub-formulas are highlighted by obscuring the sub-formulas. | |
40785 | 474 ;;(defvar calc-show-selections t) |
475 | |
42205 | 476 ;; If non-nil, commands operate only on selected portions of formulas. |
477 ;; If nil, selections displayed but ignored. | |
40785 | 478 ;;(defvar calc-use-selections t) |
479 | |
42205 | 480 ;; If non-nil, selection hides deep structure of associative formulas. |
40785 | 481 ;;(defvar calc-assoc-selections t) |
482 | |
42205 | 483 ;; If non-nil, display "Working..." for potentially slow Calculator commands. |
40785 | 484 ;;(defvar calc-display-working-message 'lots) |
485 | |
42205 | 486 ;; If non-nil, automatically execute a "why" command to explain odd results. |
40785 | 487 ;;(defvar calc-auto-why nil) |
488 | |
42205 | 489 ;; If non-nil, display timing information on each slow command. |
40785 | 490 ;;(defvar calc-timing nil) |
491 | |
492 ;; Floating-point numbers with this positive exponent or higher above the | |
493 ;; current precision are displayed in scientific notation in calc-mode. | |
494 (defvar calc-display-sci-high 0) | |
495 | |
496 ;; Floating-point numbers with this negative exponent or lower are displayed | |
497 ;; scientific notation in calc-mode. | |
498 (defvar calc-display-sci-low -3) | |
499 | |
500 | |
501 ;; List of used-defined strings to append to Calculator mode line. | |
502 (defvar calc-other-modes nil) | |
503 | |
504 ;; List of strings for Y prefix help. | |
505 (defvar calc-Y-help-msgs nil) | |
506 | |
42205 | 507 ;; t if calc-settings-file has been loaded yet. |
40785 | 508 (defvar calc-loaded-settings-file nil) |
509 | |
510 | |
511 | |
512 (defconst calc-mode-var-list '((calc-always-load-extensions nil) | |
513 (calc-mode-save-mode local) | |
514 (calc-line-numbering t) | |
515 (calc-line-breaking t) | |
516 (calc-display-just nil) | |
517 (calc-display-origin nil) | |
518 (calc-left-label "") | |
519 (calc-right-label "") | |
520 (calc-number-radix 10) | |
521 (calc-leading-zeros nil) | |
522 (calc-group-digits nil) | |
523 (calc-group-char ",") | |
524 (calc-point-char ".") | |
525 (calc-frac-format (":" nil)) | |
526 (calc-prefer-frac nil) | |
527 (calc-hms-format "%s@ %s' %s\"") | |
528 (calc-date-format ((H ":" mm C SS pp " ") | |
529 Www " " Mmm " " D ", " YYYY)) | |
530 (calc-standard-date-formats | |
531 ("N" | |
532 "<H:mm:SSpp >Www Mmm D, YYYY" | |
533 "D Mmm YYYY<, h:mm:SS>" | |
534 "Www Mmm BD< hh:mm:ss> YYYY" | |
535 "M/D/Y< H:mm:SSpp>" | |
536 "D.M.Y< h:mm:SS>" | |
537 "M-D-Y< H:mm:SSpp>" | |
538 "D-M-Y< h:mm:SS>" | |
539 "j<, h:mm:SS>" | |
540 "YYddd< hh:mm:ss>")) | |
541 (calc-float-format (float 0)) | |
542 (calc-full-float-format (float 0)) | |
543 (calc-complex-format nil) | |
544 (calc-matrix-just center) | |
545 (calc-full-vectors t) | |
546 (calc-full-trail-vectors t) | |
547 (calc-break-vectors nil) | |
548 (calc-vector-commas ",") | |
549 (calc-vector-brackets "[]") | |
550 (calc-matrix-brackets (R O)) | |
551 (calc-complex-mode cplx) | |
552 (calc-infinite-mode nil) | |
553 (calc-display-strings nil) | |
554 (calc-simplify-mode nil) | |
555 (calc-auto-recompute t) | |
556 (calc-word-size 32) | |
557 (calc-previous-modulo nil) | |
558 (calc-display-raw nil) | |
559 (calc-internal-prec 12) | |
560 (calc-angle-mode deg) | |
561 (calc-algebraic-mode nil) | |
562 (calc-incomplete-algebraic-mode nil) | |
563 (calc-symbolic-mode nil) | |
564 (calc-matrix-mode nil) | |
565 (calc-autorange-units nil) | |
566 (calc-shift-prefix nil) | |
567 (calc-window-height 7) | |
568 (calc-was-keypad-mode nil) | |
569 (calc-full-mode nil) | |
570 (calc-language nil) | |
571 (calc-language-option nil) | |
572 (calc-user-parse-tables nil) | |
573 (calc-show-selections t) | |
574 (calc-use-selections t) | |
575 (calc-assoc-selections t) | |
576 (calc-display-trail t) | |
577 (calc-display-working-message lots) | |
578 (calc-auto-why 'maybe) | |
579 (calc-timing nil) | |
580 (calc-gnuplot-default-device "default") | |
581 (calc-gnuplot-default-output "STDOUT") | |
582 (calc-gnuplot-print-device "postscript") | |
583 (calc-gnuplot-print-output "auto") | |
584 (calc-gnuplot-geometry nil) | |
585 (calc-graph-default-resolution 15) | |
586 (calc-graph-default-resolution-3d 5) | |
45578
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
587 (calc-invocation-macro nil) |
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
588 (calc-show-banner t))) |
40785 | 589 |
590 (defconst calc-local-var-list '(calc-stack | |
591 calc-stack-top | |
592 calc-undo-list | |
593 calc-redo-list | |
594 calc-always-load-extensions | |
595 calc-mode-save-mode | |
596 calc-display-raw | |
597 calc-line-numbering | |
598 calc-line-breaking | |
599 calc-display-just | |
600 calc-display-origin | |
601 calc-left-label | |
602 calc-right-label | |
603 calc-auto-why | |
604 calc-algebraic-mode | |
605 calc-incomplete-algebraic-mode | |
606 calc-symbolic-mode | |
607 calc-matrix-mode | |
608 calc-inverse-flag | |
609 calc-hyperbolic-flag | |
610 calc-keep-args-flag | |
611 calc-angle-mode | |
612 calc-number-radix | |
613 calc-leading-zeros | |
614 calc-group-digits | |
615 calc-group-char | |
616 calc-point-char | |
617 calc-frac-format | |
618 calc-prefer-frac | |
619 calc-hms-format | |
620 calc-date-format | |
621 calc-standard-date-formats | |
622 calc-float-format | |
623 calc-full-float-format | |
624 calc-complex-format | |
625 calc-matrix-just | |
626 calc-full-vectors | |
627 calc-full-trail-vectors | |
628 calc-break-vectors | |
629 calc-vector-commas | |
630 calc-vector-brackets | |
631 calc-matrix-brackets | |
632 calc-complex-mode | |
633 calc-infinite-mode | |
634 calc-display-strings | |
635 calc-simplify-mode | |
636 calc-auto-recompute | |
637 calc-autorange-units | |
638 calc-show-plain | |
639 calc-show-selections | |
640 calc-use-selections | |
641 calc-assoc-selections | |
642 calc-word-size | |
643 calc-internal-prec)) | |
644 | |
645 | |
646 (defun calc-init-base () | |
647 | |
648 ;; Verify that Calc is running on the right kind of system. | |
649 (setq calc-emacs-type-epoch (and (fboundp 'epoch::version) epoch::version) | |
650 calc-emacs-type-19 (not (or calc-emacs-type-epoch | |
651 (string-lessp emacs-version "19"))) | |
652 calc-emacs-type-lucid (not (not (string-match "Lucid" emacs-version))) | |
653 calc-emacs-type-gnu19 (and calc-emacs-type-19 | |
654 (not calc-emacs-type-lucid))) | |
655 | |
656 ;; Set up the standard keystroke (M-#) to run the Calculator, if that key | |
657 ;; has not yet been bound to anything. For best results, the user should | |
658 ;; do this before Calc is even loaded, so that M-# can auto-load Calc. | |
659 (or (global-key-binding "\e#") | |
660 (global-set-key "\e#" 'calc-dispatch)) | |
661 | |
662 ;; Set up the autoloading linkage. | |
663 (let ((name (and (fboundp 'calc-dispatch) | |
664 (eq (car-safe (symbol-function 'calc-dispatch)) 'autoload) | |
665 (nth 1 (symbol-function 'calc-dispatch)))) | |
666 (p load-path)) | |
667 | |
668 ;; If Calc files exist on the load-path, we're all set. | |
669 (while (and p (not (file-exists-p | |
670 (expand-file-name "calc-misc.elc" (car p))))) | |
671 (setq p (cdr p))) | |
672 (or p | |
673 | |
674 ;; If Calc is autoloaded using a path name, look there for Calc files. | |
675 ;; This works for both relative ("calc/calc.elc") and absolute paths. | |
676 (and name (file-name-directory name) | |
677 (let ((p2 load-path) | |
678 (name2 (concat (file-name-directory name) | |
679 "calc-misc.elc"))) | |
680 (while (and p2 (not (file-exists-p | |
681 (expand-file-name name2 (car p2))))) | |
682 (setq p2 (cdr p2))) | |
45769 | 683 (when p2 |
684 (setq load-path (nconc load-path | |
685 (list | |
686 (directory-file-name | |
687 (file-name-directory | |
688 (expand-file-name | |
689 name (car p2)))))))))) | |
40785 | 690 |
691 ;; If calc-autoload-directory is given, use that (and hope it works!). | |
692 (and calc-autoload-directory | |
693 (not (equal calc-autoload-directory "")) | |
694 (setq load-path (nconc load-path | |
695 (list (directory-file-name | |
696 calc-autoload-directory))))))) | |
697 | |
698 ;; The following modes use specially-formatted data. | |
699 (put 'calc-mode 'mode-class 'special) | |
700 (put 'calc-trail-mode 'mode-class 'special) | |
701 | |
702 ;; Define "inexact-result" as an e-lisp error symbol. | |
703 (put 'inexact-result 'error-conditions '(error inexact-result calc-error)) | |
704 (put 'inexact-result 'error-message "Calc internal error (inexact-result)") | |
705 | |
706 ;; Define "math-overflow" and "math-underflow" as e-lisp error symbols. | |
707 (put 'math-overflow 'error-conditions '(error math-overflow calc-error)) | |
708 (put 'math-overflow 'error-message "Floating-point overflow occurred") | |
709 (put 'math-underflow 'error-conditions '(error math-underflow calc-error)) | |
710 (put 'math-underflow 'error-message "Floating-point underflow occurred") | |
711 | |
41283
1c09d8ddd155
(toplevel): Add comment and version header.
Colin Walters <walters@gnu.org>
parents:
41270
diff
changeset
|
712 (setq calc-version "2.02g" |
1c09d8ddd155
(toplevel): Add comment and version header.
Colin Walters <walters@gnu.org>
parents:
41270
diff
changeset
|
713 calc-version-date "Mon Nov 19 2001" |
40785 | 714 calc-trail-pointer nil ; "Current" entry in trail buffer. |
715 calc-trail-overlay nil ; Value of overlay-arrow-string. | |
716 calc-undo-list nil ; List of previous operations for undo. | |
717 calc-redo-list nil ; List of recent undo operations. | |
718 calc-main-buffer nil ; Pointer to Calculator buffer. | |
719 calc-trail-buffer nil ; Pointer to Calc Trail buffer. | |
720 calc-why nil ; Explanations of most recent errors. | |
721 calc-next-why nil | |
722 calc-inverse-flag nil | |
723 calc-hyperbolic-flag nil | |
724 calc-keep-args-flag nil | |
725 calc-function-open "(" | |
726 calc-function-close ")" | |
727 calc-language-output-filter nil | |
728 calc-language-input-filter nil | |
729 calc-radix-formatter nil | |
730 calc-last-kill nil ; Last number killed in calc-mode. | |
731 calc-previous-alg-entry nil ; Previous algebraic entry. | |
732 calc-dollar-values nil ; Values to be used for '$'. | |
733 calc-dollar-used nil ; Highest order of '$' that occurred. | |
734 calc-hashes-used nil ; Highest order of '#' that occurred. | |
735 calc-quick-prev-results nil ; Previous results from Quick Calc. | |
736 calc-said-hello nil ; Has welcome message been said yet? | |
737 calc-executing-macro nil ; Kbd macro executing from "K" key. | |
738 calc-any-selections nil ; Nil means no selections present. | |
739 calc-help-phase 0 ; Count of consecutive "?" keystrokes. | |
740 calc-full-help-flag nil ; Executing calc-full-help? | |
741 calc-refresh-count 0 ; Count of calc-refresh calls. | |
742 calc-display-dirty nil | |
743 calc-prepared-composition nil | |
744 calc-selection-cache-default-entry nil | |
745 calc-embedded-info nil | |
746 calc-embedded-active nil | |
747 calc-standalone-flag nil | |
748 var-EvalRules nil | |
749 math-eval-rules-cache-tag t | |
750 math-radix-explicit-format t | |
751 math-expr-function-mapping nil | |
752 math-expr-variable-mapping nil | |
753 math-read-expr-quotes nil | |
754 math-working-step nil | |
755 math-working-step-2 nil | |
756 var-i '(special-const (math-imaginary 1)) | |
757 var-pi '(special-const (math-pi)) | |
758 var-e '(special-const (math-e)) | |
759 var-phi '(special-const (math-phi)) | |
760 var-gamma '(special-const (math-gamma-const)) | |
761 var-Modes '(special-const (math-get-modes-vec))) | |
762 | |
763 (mapcar (function (lambda (v) (or (boundp (car v)) (set (car v) (nth 1 v))))) | |
764 calc-mode-var-list) | |
765 (mapcar (function (lambda (v) (or (boundp v) (set v nil)))) | |
766 calc-local-var-list) | |
767 | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
768 (unless (boundp 'calc-mode-map) |
40785 | 769 (setq calc-mode-map (make-keymap)) |
770 (suppress-keymap calc-mode-map t) | |
771 (define-key calc-mode-map "+" 'calc-plus) | |
772 (define-key calc-mode-map "-" 'calc-minus) | |
773 (define-key calc-mode-map "*" 'calc-times) | |
774 (define-key calc-mode-map "/" 'calc-divide) | |
775 (define-key calc-mode-map "%" 'calc-mod) | |
776 (define-key calc-mode-map "&" 'calc-inv) | |
777 (define-key calc-mode-map "^" 'calc-power) | |
778 (define-key calc-mode-map "\M-%" 'calc-percent) | |
779 (define-key calc-mode-map "e" 'calcDigit-start) | |
780 (define-key calc-mode-map "i" 'calc-info) | |
781 (define-key calc-mode-map "n" 'calc-change-sign) | |
782 (define-key calc-mode-map "q" 'calc-quit) | |
783 (define-key calc-mode-map "Y" 'nil) | |
784 (define-key calc-mode-map "Y?" 'calc-shift-Y-prefix-help) | |
785 (define-key calc-mode-map "?" 'calc-help) | |
786 (define-key calc-mode-map " " 'calc-enter) | |
787 (define-key calc-mode-map "'" 'calc-algebraic-entry) | |
788 (define-key calc-mode-map "$" 'calc-auto-algebraic-entry) | |
789 (define-key calc-mode-map "\"" 'calc-auto-algebraic-entry) | |
790 (define-key calc-mode-map "\t" 'calc-roll-down) | |
791 (define-key calc-mode-map "\M-\t" 'calc-roll-up) | |
792 (define-key calc-mode-map "\C-m" 'calc-enter) | |
793 (define-key calc-mode-map "\M-\C-m" 'calc-last-args-stub) | |
794 (define-key calc-mode-map "\C-j" 'calc-over) | |
795 | |
796 (mapcar (function | |
797 (lambda (x) | |
798 (define-key calc-mode-map (char-to-string x) 'undefined))) | |
799 "lOW") | |
800 (mapcar (function | |
801 (lambda (x) | |
802 (define-key calc-mode-map (char-to-string x) | |
803 'calc-missing-key))) | |
804 (concat "ABCDEFGHIJKLMNPQRSTUVXZabcdfghjkmoprstuvwxyz" | |
805 ":\\|!()[]<>{},;=~`\C-k\M-k\C-w\M-w\C-y\C-_")) | |
806 (mapcar (function | |
807 (lambda (x) | |
808 (define-key calc-mode-map (char-to-string x) 'calcDigit-start))) | |
809 "_0123456789.#@") | |
810 | |
811 (setq calc-digit-map (make-keymap)) | |
812 (if calc-emacs-type-lucid | |
813 (map-keymap (function | |
814 (lambda (keys bind) | |
815 (define-key calc-digit-map keys | |
816 (if (eq bind 'undefined) | |
817 'undefined 'calcDigit-nondigit)))) | |
818 calc-mode-map) | |
819 (let ((cmap (if calc-emacs-type-19 (nth 1 calc-mode-map) calc-mode-map)) | |
820 (dmap (if calc-emacs-type-19 (nth 1 calc-digit-map) | |
821 calc-digit-map)) | |
822 (i 0)) | |
823 (while (< i 128) | |
824 (aset dmap i | |
825 (if (eq (aref cmap i) 'undefined) | |
826 'undefined 'calcDigit-nondigit)) | |
827 (setq i (1+ i))))) | |
828 (mapcar (function | |
829 (lambda (x) | |
830 (define-key calc-digit-map (char-to-string x) | |
831 'calcDigit-key))) | |
832 "_0123456789.e+-:n#@oh'\"mspM") | |
833 (mapcar (function | |
834 (lambda (x) | |
835 (define-key calc-digit-map (char-to-string x) | |
836 'calcDigit-letter))) | |
837 "abcdfgijklqrtuvwxyzABCDEFGHIJKLNOPQRSTUVWXYZ") | |
838 (define-key calc-digit-map "'" 'calcDigit-algebraic) | |
839 (define-key calc-digit-map "`" 'calcDigit-edit) | |
840 (define-key calc-digit-map "\C-g" 'abort-recursive-edit) | |
841 | |
842 (mapcar (function | |
843 (lambda (x) | |
844 (condition-case err | |
845 (progn | |
846 (define-key calc-digit-map x 'calcDigit-backspace) | |
847 (define-key calc-mode-map x 'calc-pop) | |
848 (define-key calc-mode-map | |
849 (if (vectorp x) | |
850 (if calc-emacs-type-lucid | |
851 (if (= (length x) 1) | |
852 (vector (if (consp (aref x 0)) | |
853 (cons 'meta (aref x 0)) | |
854 (list 'meta (aref x 0)))) | |
855 "\e\C-d") | |
856 (vconcat "\e" x)) | |
857 (concat "\e" x)) | |
858 'calc-pop-above)) | |
859 (error nil)))) | |
860 (if calc-scan-for-dels | |
861 (append (where-is-internal 'delete-backward-char global-map) | |
862 (where-is-internal 'backward-delete-char global-map) | |
863 '("\C-d")) | |
864 '("\177" "\C-d"))) | |
865 | |
866 (setq calc-dispatch-map (make-keymap)) | |
867 (mapcar (function | |
868 (lambda (x) | |
869 (define-key calc-dispatch-map (char-to-string (car x)) (cdr x)) | |
45769 | 870 (when (string-match "abcdefhijklnopqrstuwxyz" |
871 (char-to-string (car x))) | |
872 (define-key calc-dispatch-map | |
873 (char-to-string (- (car x) ?a -1)) (cdr x))) | |
40785 | 874 (define-key calc-dispatch-map (format "\e%c" (car x)) (cdr x)))) |
875 '( ( ?a . calc-embedded-activate ) | |
876 ( ?b . calc-big-or-small ) | |
877 ( ?c . calc ) | |
878 ( ?d . calc-embedded-duplicate ) | |
879 ( ?e . calc-embedded ) | |
880 ( ?f . calc-embedded-new-formula ) | |
881 ( ?g . calc-grab-region ) | |
882 ( ?h . calc-dispatch-help ) | |
883 ( ?i . calc-info ) | |
884 ( ?j . calc-embedded-select ) | |
885 ( ?k . calc-keypad ) | |
886 ( ?l . calc-load-everything ) | |
887 ( ?m . read-kbd-macro ) | |
888 ( ?n . calc-embedded-next ) | |
889 ( ?o . calc-other-window ) | |
890 ( ?p . calc-embedded-previous ) | |
891 ( ?q . quick-calc ) | |
892 ( ?r . calc-grab-rectangle ) | |
893 ( ?s . calc-info-summary ) | |
894 ( ?t . calc-tutorial ) | |
895 ( ?u . calc-embedded-update-formula ) | |
896 ( ?w . calc-embedded-word ) | |
897 ( ?x . calc-quit ) | |
898 ( ?y . calc-copy-to-buffer ) | |
899 ( ?z . calc-user-invocation ) | |
900 ( ?= . calc-embedded-update-formula ) | |
901 ( ?\' . calc-embedded-new-formula ) | |
902 ( ?\` . calc-embedded-edit ) | |
903 ( ?: . calc-grab-sum-down ) | |
904 ( ?_ . calc-grab-sum-across ) | |
905 ( ?0 . calc-reset ) | |
906 ( ?# . calc-same-interface ) | |
907 ( ?? . calc-dispatch-help ) )) | |
908 ) | |
909 | |
910 (autoload 'calc-extensions "calc-ext") | |
911 (autoload 'calc-need-macros "calc-macs") | |
912 | |
913 ;;;; (Autoloads here) | |
914 (mapcar (function (lambda (x) | |
915 (mapcar (function (lambda (func) | |
916 (autoload func (car x)))) (cdr x)))) | |
917 '( | |
918 | |
919 ("calc-aent" calc-Need-calc-aent calc-alg-digit-entry calc-alg-entry | |
920 calc-check-user-syntax calc-do-alg-entry calc-do-calc-eval | |
921 calc-do-quick-calc calc-match-user-syntax math-build-parse-table | |
922 math-find-user-tokens math-read-expr-list math-read-exprs math-read-if | |
923 math-read-token math-remove-dashes) | |
924 | |
44249 | 925 ("calc-misc" calc-Need-calc-misc |
40785 | 926 calc-do-handle-whys calc-do-refresh calc-num-prefix-name |
927 calc-record-list calc-record-why calc-report-bug calc-roll-down-stack | |
928 calc-roll-up-stack calc-temp-minibuffer-message calcFunc-floor | |
929 calcFunc-inv calcFunc-trunc math-concat math-constp math-div2 | |
930 math-div2-bignum math-do-working math-evenp math-fixnatnump | |
931 math-fixnump math-floor math-imod math-ipow math-looks-negp math-mod | |
932 math-negp math-posp math-pow math-read-radix-digit math-reject-arg | |
933 math-trunc math-zerop) | |
934 | |
935 )) | |
936 | |
937 (mapcar (function (lambda (x) | |
938 (mapcar (function (lambda (cmd) | |
939 (autoload cmd (car x) nil t))) (cdr x)))) | |
940 '( | |
941 | |
942 ("calc-aent" calc-algebraic-entry calc-auto-algebraic-entry | |
943 calcDigit-algebraic calcDigit-edit) | |
944 | |
945 ("calc-misc" another-calc calc-big-or-small calc-dispatch-help | |
946 calc-help calc-info calc-info-summary calc-inv calc-last-args-stub | |
947 calc-missing-key calc-mod calc-other-window calc-over calc-percent | |
948 calc-pop-above calc-power calc-roll-down calc-roll-up | |
949 calc-shift-Y-prefix-help calc-tutorial calcDigit-letter | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
950 report-calc-bug)))) |
40785 | 951 |
952 (calc-init-base) | |
953 | |
954 | |
955 ;;;###autoload (global-set-key "\e#" 'calc-dispatch) | |
956 | |
957 ;;;###autoload | |
958 (defun calc-dispatch (&optional arg) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
959 "Invoke the GNU Emacs Calculator. See `calc-dispatch-help' for details." |
40785 | 960 (interactive "P") |
961 (sit-for echo-keystrokes) | |
962 (condition-case err ; look for other keys bound to calc-dispatch | |
963 (let ((keys (this-command-keys))) | |
45769 | 964 (unless (or (not (stringp keys)) |
965 (string-match "\\`\C-u\\|\\`\e[-0-9#]\\|`[\M--\M-0-\M-9]" keys) | |
966 (eq (lookup-key calc-dispatch-map keys) 'calc-same-interface)) | |
967 (when (and (string-match "\\`[\C-@-\C-_]" keys) | |
968 (symbolp | |
969 (lookup-key calc-dispatch-map (substring keys 0 1)))) | |
970 (define-key calc-dispatch-map (substring keys 0 1) nil)) | |
971 (define-key calc-dispatch-map keys 'calc-same-interface))) | |
40785 | 972 (error nil)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
973 (calc-do-dispatch arg)) |
40785 | 974 |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
975 (defvar calc-dispatch-help nil) |
40785 | 976 (defun calc-do-dispatch (arg) |
977 (let ((key (calc-read-key-sequence | |
978 (if calc-dispatch-help | |
979 "Calc options: Calc, Keypad, Quick, Embed; eXit; Info, Tutorial; Grab; ?=more" | |
980 (format "%s (Type ? for a list of Calc options)" | |
981 (key-description (this-command-keys)))) | |
982 calc-dispatch-map))) | |
983 (setq key (lookup-key calc-dispatch-map key)) | |
984 (message "") | |
985 (if key | |
986 (progn | |
987 (or (commandp key) (calc-extensions)) | |
988 (call-interactively key)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
989 (beep)))) |
40785 | 990 |
991 (defun calc-read-key-sequence (prompt map) | |
992 (let ((prompt2 (format "%s " (key-description (this-command-keys)))) | |
993 (glob (current-global-map)) | |
994 (loc (current-local-map))) | |
995 (or (input-pending-p) (message prompt)) | |
996 (let ((key (calc-read-key t))) | |
997 (calc-unread-command (cdr key)) | |
998 (unwind-protect | |
999 (progn | |
1000 (use-global-map map) | |
1001 (use-local-map nil) | |
1002 (read-key-sequence | |
1003 (if (commandp (key-binding (if calc-emacs-type-19 | |
1004 (vector (cdr key)) | |
1005 (char-to-string (cdr key))))) | |
1006 "" prompt2))) | |
1007 (use-global-map glob) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1008 (use-local-map loc))))) |
40785 | 1009 |
1010 | |
1011 | |
1012 (defun calc-mode () | |
1013 "Calculator major mode. | |
1014 | |
1015 This is an RPN calculator featuring arbitrary-precision integer, rational, | |
1016 floating-point, complex, matrix, and symbolic arithmetic. | |
1017 | |
1018 RPN calculation: 2 RET 3 + produces 5. | |
1019 Algebraic style: ' 2+3 RET produces 5. | |
1020 | |
1021 Basic operators are +, -, *, /, ^, & (reciprocal), % (modulo), n (change-sign). | |
1022 | |
1023 Press ? repeatedly for more complete help. Press `h i' to read the | |
1024 Calc manual on-line, `h s' to read the summary, or `h t' for the tutorial. | |
1025 | |
1026 Notations: 3.14e6 3.14 * 10^6 | |
1027 _23 negative number -23 (or type `23 n') | |
1028 17:3 the fraction 17/3 | |
1029 5:2:3 the fraction 5 and 2/3 | |
1030 16#12C the integer 12C base 16 = 300 base 10 | |
1031 8#177:100 the fraction 177:100 base 8 = 127:64 base 10 | |
1032 (2, 4) complex number 2 + 4i | |
1033 (2; 4) polar complex number (r; theta) | |
1034 [1, 2, 3] vector ([[1, 2], [3, 4]] is a matrix) | |
1035 [1 .. 4) semi-open interval, 1 <= x < 4 | |
1036 2 +/- 3 (p key) number with mean 2, standard deviation 3 | |
1037 2 mod 3 (M key) number 2 computed modulo 3 | |
1038 <1 jan 91> Date form (enter using ' key) | |
1039 | |
1040 | |
1041 \\{calc-mode-map} | |
1042 " | |
1043 (interactive) | |
1044 (mapcar (function | |
1045 (lambda (v) (set-default v (symbol-value v)))) calc-local-var-list) | |
1046 (kill-all-local-variables) | |
1047 (use-local-map (if (eq calc-algebraic-mode 'total) | |
1048 (progn (calc-extensions) calc-alg-map) calc-mode-map)) | |
1049 (mapcar (function (lambda (v) (make-local-variable v))) calc-local-var-list) | |
1050 (make-local-variable 'overlay-arrow-position) | |
1051 (make-local-variable 'overlay-arrow-string) | |
47539
663c306c80c6
(calc-mode): Add font-lock-defontify to change-major-mode-hook.
Colin Walters <walters@gnu.org>
parents:
46807
diff
changeset
|
1052 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) |
40785 | 1053 (setq truncate-lines t) |
1054 (setq buffer-read-only t) | |
1055 (setq major-mode 'calc-mode) | |
1056 (setq mode-name "Calculator") | |
1057 (setq calc-stack-top (length (or (memq (assq 'top-of-stack calc-stack) | |
1058 calc-stack) | |
1059 (setq calc-stack (list (list 'top-of-stack | |
1060 1 nil)))))) | |
1061 (setq calc-stack-top (- (length calc-stack) calc-stack-top -1)) | |
1062 (or calc-loaded-settings-file | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1063 (null calc-settings-file) |
40785 | 1064 (string-match "\\.emacs" calc-settings-file) |
1065 (progn | |
1066 (setq calc-loaded-settings-file t) | |
1067 (load calc-settings-file t))) ; t = missing-ok | |
1068 (if (and (eq window-system 'x) (boundp 'mouse-map)) | |
1069 (substitute-key-definition 'x-paste-text 'calc-x-paste-text | |
1070 mouse-map)) | |
1071 (let ((p command-line-args)) | |
1072 (while p | |
1073 (and (equal (car p) "-f") | |
1074 (string-match "calc" (nth 1 p)) | |
1075 (string-match "full" (nth 1 p)) | |
1076 (setq calc-standalone-flag t)) | |
1077 (setq p (cdr p)))) | |
1078 (run-hooks 'calc-mode-hook) | |
1079 (calc-refresh t) | |
1080 (calc-set-mode-line) | |
1081 ;; The calc-defs variable is a relic. Use calc-define properties instead. | |
45769 | 1082 (when (and (boundp 'calc-defs) |
1083 calc-defs) | |
1084 (message "Evaluating calc-defs...") | |
1085 (calc-need-macros) | |
1086 (eval (cons 'progn calc-defs)) | |
1087 (setq calc-defs nil) | |
1088 (calc-set-mode-line)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1089 (calc-check-defines)) |
40785 | 1090 |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1091 (defvar calc-check-defines 'calc-check-defines) ; suitable for run-hooks |
40785 | 1092 (defun calc-check-defines () |
1093 (if (symbol-plist 'calc-define) | |
1094 (let ((plist (copy-sequence (symbol-plist 'calc-define)))) | |
1095 (while (and plist (null (nth 1 plist))) | |
1096 (setq plist (cdr (cdr plist)))) | |
1097 (if plist | |
1098 (save-excursion | |
1099 (calc-extensions) | |
1100 (calc-need-macros) | |
1101 (set-buffer "*Calculator*") | |
1102 (while plist | |
1103 (put 'calc-define (car plist) nil) | |
1104 (eval (nth 1 plist)) | |
1105 (setq plist (cdr (cdr plist)))) | |
1106 ;; See if this has added any more calc-define properties. | |
1107 (calc-check-defines)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1108 (setplist 'calc-define nil))))) |
40785 | 1109 |
1110 (defun calc-trail-mode (&optional buf) | |
1111 "Calc Trail mode. | |
1112 This mode is used by the *Calc Trail* buffer, which records all results | |
1113 obtained by the GNU Emacs Calculator. | |
1114 | |
1115 Calculator commands beginning with the `t' key are used to manipulate | |
1116 the Trail. | |
1117 | |
1118 This buffer uses the same key map as the *Calculator* buffer; calculator | |
1119 commands given here will actually operate on the *Calculator* stack." | |
1120 (interactive) | |
1121 (fundamental-mode) | |
1122 (use-local-map calc-mode-map) | |
1123 (setq major-mode 'calc-trail-mode) | |
1124 (setq mode-name "Calc Trail") | |
1125 (setq truncate-lines t) | |
1126 (setq buffer-read-only t) | |
1127 (make-local-variable 'overlay-arrow-position) | |
1128 (make-local-variable 'overlay-arrow-string) | |
45769 | 1129 (set (make-local-variable 'font-lock-defaults) |
1130 '(nil t nil nil nil (font-lock-core-only . t))) | |
1131 (when buf | |
1132 (set (make-local-variable 'calc-main-buffer) buf)) | |
1133 (when (= (buffer-size) 0) | |
1134 (let ((buffer-read-only nil)) | |
1135 (insert (propertize (concat "Emacs Calculator v" calc-version | |
1136 " by Dave Gillespie\n") | |
1137 'font-lock-face 'italic)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1138 (run-hooks 'calc-trail-mode-hook)) |
40785 | 1139 |
1140 (defun calc-create-buffer () | |
1141 (set-buffer (get-buffer-create "*Calculator*")) | |
1142 (or (eq major-mode 'calc-mode) | |
1143 (calc-mode)) | |
1144 (setq max-lisp-eval-depth (max max-lisp-eval-depth 1000)) | |
45769 | 1145 (when calc-always-load-extensions |
1146 (calc-extensions)) | |
1147 (when calc-language | |
1148 (calc-extensions) | |
1149 (calc-set-language calc-language calc-language-option t))) | |
40785 | 1150 |
1151 ;;;###autoload | |
1152 (defun calc (&optional arg full-display interactive) | |
1153 "The Emacs Calculator. Full documentation is listed under \"calc-mode\"." | |
1154 (interactive "P") | |
1155 (if arg | |
45769 | 1156 (unless (eq arg 0) |
1157 (calc-extensions) | |
1158 (if (= (prefix-numeric-value arg) -1) | |
1159 (calc-grab-region (region-beginning) (region-end) nil) | |
1160 (when (= (prefix-numeric-value arg) -2) | |
1161 (calc-keypad)))) | |
1162 (when (get-buffer-window "*Calc Keypad*") | |
1163 (calc-keypad) | |
1164 (set-buffer (window-buffer (selected-window)))) | |
40785 | 1165 (if (eq major-mode 'calc-mode) |
1166 (calc-quit) | |
1167 (let ((oldbuf (current-buffer))) | |
1168 (calc-create-buffer) | |
1169 (setq calc-was-keypad-mode nil) | |
1170 (if (or (eq full-display t) | |
1171 (and (null full-display) calc-full-mode)) | |
1172 (switch-to-buffer (current-buffer) t) | |
1173 (if (get-buffer-window (current-buffer)) | |
1174 (select-window (get-buffer-window (current-buffer))) | |
1175 (if (and (boundp 'calc-window-hook) calc-window-hook) | |
1176 (run-hooks 'calc-window-hook) | |
1177 (let ((w (get-largest-window))) | |
1178 (if (and pop-up-windows | |
1179 (> (window-height w) | |
1180 (+ window-min-height calc-window-height 2))) | |
1181 (progn | |
1182 (setq w (split-window w | |
1183 (- (window-height w) | |
1184 calc-window-height 2) | |
1185 nil)) | |
1186 (set-window-buffer w (current-buffer)) | |
1187 (select-window w)) | |
1188 (pop-to-buffer (current-buffer))))))) | |
1189 (save-excursion | |
1190 (set-buffer (calc-trail-buffer)) | |
1191 (and calc-display-trail | |
40999
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
1192 (= (window-width) (frame-width)) |
40785 | 1193 (calc-trail-display 1 t))) |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1194 (message "Welcome to the GNU Emacs Calculator! Press `?' or `h' for help, `q' to quit") |
40785 | 1195 (run-hooks 'calc-start-hook) |
1196 (and (windowp full-display) | |
1197 (window-point full-display) | |
1198 (select-window full-display)) | |
1199 (calc-check-defines) | |
45769 | 1200 (when (and calc-said-hello |
1201 (or (interactive-p) interactive)) | |
1202 (sit-for 2) | |
1203 (message "")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1204 (setq calc-said-hello t))))) |
40785 | 1205 |
1206 ;;;###autoload | |
1207 (defun full-calc () | |
1208 "Invoke the Calculator and give it a full-sized window." | |
1209 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1210 (calc nil t (interactive-p))) |
40785 | 1211 |
1212 (defun calc-same-interface (arg) | |
1213 "Invoke the Calculator using the most recent interface (calc or calc-keypad)." | |
1214 (interactive "P") | |
1215 (if (and (equal (buffer-name) "*Gnuplot Trail*") | |
1216 (> (recursion-depth) 0)) | |
1217 (exit-recursive-edit) | |
1218 (if (eq major-mode 'calc-edit-mode) | |
1219 (calc-edit-finish arg) | |
1220 (if (eq major-mode 'MacEdit-mode) | |
1221 (MacEdit-finish-edit) | |
1222 (if calc-was-keypad-mode | |
1223 (calc-keypad) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1224 (calc arg calc-full-mode t)))))) |
40785 | 1225 |
1226 | |
1227 (defun calc-quit (&optional non-fatal) | |
1228 (interactive) | |
1229 (and calc-standalone-flag (not non-fatal) | |
1230 (save-buffers-kill-emacs nil)) | |
1231 (if (and (equal (buffer-name) "*Gnuplot Trail*") | |
1232 (> (recursion-depth) 0)) | |
1233 (exit-recursive-edit)) | |
1234 (if (eq major-mode 'calc-edit-mode) | |
1235 (calc-edit-cancel) | |
1236 (if (eq major-mode 'MacEdit-mode) | |
1237 (MacEdit-cancel-edit) | |
1238 (if (and (interactive-p) | |
1239 calc-embedded-info | |
1240 (eq (current-buffer) (aref calc-embedded-info 0))) | |
1241 (calc-embedded nil) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1242 (unless (eq major-mode 'calc-mode) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1243 (calc-create-buffer)) |
40785 | 1244 (run-hooks 'calc-end-hook) |
1245 (setq calc-undo-list nil calc-redo-list nil) | |
1246 (mapcar (function (lambda (v) (set-default v (symbol-value v)))) | |
1247 calc-local-var-list) | |
1248 (let ((buf (current-buffer)) | |
1249 (win (get-buffer-window (current-buffer))) | |
1250 (kbuf (get-buffer "*Calc Keypad*"))) | |
1251 (delete-windows-on (calc-trail-buffer)) | |
1252 (if (and win | |
40999
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
1253 (< (window-height win) (1- (frame-height))) |
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
1254 (= (window-width win) (frame-width)) ; avoid calc-keypad |
40785 | 1255 (not (get-buffer-window "*Calc Keypad*"))) |
1256 (setq calc-window-height (- (window-height win) 2))) | |
44247
b50c25ecef92
(calc-was-split): Var deleted.
Colin Walters <walters@gnu.org>
parents:
43185
diff
changeset
|
1257 (progn |
40785 | 1258 (delete-windows-on buf) |
1259 (delete-windows-on kbuf)) | |
1260 (bury-buffer buf) | |
1261 (bury-buffer calc-trail-buffer) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1262 (and kbuf (bury-buffer kbuf))))))) |
40785 | 1263 |
1264 ;;;###autoload | |
1265 (defun quick-calc () | |
1266 "Do a quick calculation in the minibuffer without invoking full Calculator." | |
1267 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1268 (calc-do-quick-calc)) |
40785 | 1269 |
1270 ;;;###autoload | |
1271 (defun calc-eval (str &optional separator &rest args) | |
1272 "Do a quick calculation and return the result as a string. | |
1273 Return value will either be the formatted result in string form, | |
1274 or a list containing a character position and an error message in string form." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1275 (calc-do-calc-eval str separator args)) |
40785 | 1276 |
1277 ;;;###autoload | |
1278 (defun calc-keypad () | |
1279 "Invoke the Calculator in \"visual keypad\" mode. | |
1280 This is most useful in the X window system. | |
1281 In this mode, click on the Calc \"buttons\" using the left mouse button. | |
1282 Or, position the cursor manually and do M-x calc-keypad-press." | |
1283 (interactive) | |
1284 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1285 (calc-do-keypad calc-full-mode (interactive-p))) |
40785 | 1286 |
1287 ;;;###autoload | |
1288 (defun full-calc-keypad () | |
1289 "Invoke the Calculator in full-screen \"visual keypad\" mode. | |
1290 See calc-keypad for details." | |
1291 (interactive) | |
1292 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1293 (calc-do-keypad t (interactive-p))) |
40785 | 1294 |
1295 | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1296 (defvar calc-aborted-prefix nil) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1297 (defvar calc-start-time nil) |
40785 | 1298 ;;; Note that modifications to this function may break calc-pass-errors. |
1299 (defun calc-do (do-body &optional do-slow) | |
1300 (calc-check-defines) | |
1301 (let* ((calc-command-flags nil) | |
1302 (calc-start-time (and calc-timing (not calc-start-time) | |
1303 (calc-extensions) | |
1304 (current-time-string))) | |
1305 (gc-cons-threshold (max gc-cons-threshold | |
1306 (if calc-timing 2000000 100000)))) | |
1307 (setq calc-aborted-prefix "") | |
1308 (unwind-protect | |
1309 (condition-case err | |
1310 (save-excursion | |
1311 (if calc-embedded-info | |
1312 (calc-embedded-select-buffer) | |
1313 (calc-select-buffer)) | |
1314 (and (eq calc-algebraic-mode 'total) | |
1315 (calc-extensions) | |
1316 (use-local-map calc-alg-map)) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1317 (when (and do-slow calc-display-working-message) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1318 (message "Working...") |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1319 (calc-set-command-flag 'clear-message)) |
40785 | 1320 (funcall do-body) |
1321 (setq calc-aborted-prefix nil) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1322 (when (memq 'renum-stack calc-command-flags) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1323 (calc-renumber-stack)) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1324 (when (memq 'clear-message calc-command-flags) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1325 (message ""))) |
40785 | 1326 (error |
1327 (if (and (eq (car err) 'error) | |
1328 (stringp (nth 1 err)) | |
1329 (string-match "max-specpdl-size\\|max-lisp-eval-depth" | |
1330 (nth 1 err))) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1331 (error "Computation got stuck or ran too long. Type `M' to increase the limit") |
40785 | 1332 (setq calc-aborted-prefix nil) |
1333 (signal (car err) (cdr err))))) | |
1334 (setq calc-old-aborted-prefix calc-aborted-prefix) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1335 (when calc-aborted-prefix |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1336 (calc-record "<Aborted>" calc-aborted-prefix)) |
40785 | 1337 (and calc-start-time |
1338 (let* ((calc-internal-prec 12) | |
1339 (calc-date-format nil) | |
1340 (end-time (current-time-string)) | |
1341 (time (if (equal calc-start-time end-time) | |
1342 0 | |
1343 (math-sub | |
1344 (calcFunc-unixtime (math-parse-date end-time) 0) | |
1345 (calcFunc-unixtime (math-parse-date calc-start-time) | |
1346 0))))) | |
1347 (if (math-lessp 1 time) | |
1348 (calc-record time "(t)")))) | |
1349 (or (memq 'no-align calc-command-flags) | |
1350 (eq major-mode 'calc-trail-mode) | |
1351 (calc-align-stack-window)) | |
1352 (and (memq 'position-point calc-command-flags) | |
1353 (if (eq major-mode 'calc-mode) | |
1354 (progn | |
1355 (goto-line calc-final-point-line) | |
1356 (move-to-column calc-final-point-column)) | |
1357 (save-excursion | |
1358 (calc-select-buffer) | |
1359 (goto-line calc-final-point-line) | |
1360 (move-to-column calc-final-point-column)))) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1361 (unless (memq 'keep-flags calc-command-flags) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1362 (save-excursion |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1363 (calc-select-buffer) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1364 (setq calc-inverse-flag nil |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1365 calc-hyperbolic-flag nil |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1366 calc-keep-args-flag nil))) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1367 (when (memq 'do-edit calc-command-flags) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1368 (switch-to-buffer (get-buffer-create "*Calc Edit*"))) |
40785 | 1369 (calc-set-mode-line) |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1370 (when calc-embedded-info |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1371 (calc-embedded-finish-command)))) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1372 (identity nil)) ; allow a GC after timing is done |
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1373 |
40785 | 1374 |
1375 (defun calc-set-command-flag (f) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1376 (unless (memq f calc-command-flags) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1377 (setq calc-command-flags (cons f calc-command-flags)))) |
40785 | 1378 |
1379 (defun calc-select-buffer () | |
1380 (or (eq major-mode 'calc-mode) | |
1381 (if calc-main-buffer | |
1382 (set-buffer calc-main-buffer) | |
1383 (let ((buf (get-buffer "*Calculator*"))) | |
1384 (if buf | |
1385 (set-buffer buf) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1386 (error "Calculator buffer not available")))))) |
40785 | 1387 |
1388 (defun calc-cursor-stack-index (&optional index) | |
1389 (goto-char (point-max)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1390 (forward-line (- (calc-substack-height (or index 1))))) |
40785 | 1391 |
1392 (defun calc-stack-size () | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1393 (- (length calc-stack) calc-stack-top)) |
40785 | 1394 |
1395 (defun calc-substack-height (n) | |
1396 (let ((sum 0) | |
1397 (stack calc-stack)) | |
1398 (setq n (+ n calc-stack-top)) | |
1399 (while (and (> n 0) stack) | |
1400 (setq sum (+ sum (nth 1 (car stack))) | |
1401 n (1- n) | |
1402 stack (cdr stack))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1403 sum)) |
40785 | 1404 |
1405 (defun calc-set-mode-line () | |
1406 (save-excursion | |
1407 (calc-select-buffer) | |
1408 (let* ((fmt (car calc-float-format)) | |
1409 (figs (nth 1 calc-float-format)) | |
1410 (new-mode-string | |
1411 (format "Calc%s%s: %d %s %-14s" | |
1412 (if calc-embedded-info "Embed" "") | |
1413 (if (and (> (length (buffer-name)) 12) | |
1414 (equal (substring (buffer-name) 0 12) | |
1415 "*Calculator*")) | |
1416 (substring (buffer-name) 12) | |
1417 "") | |
1418 calc-internal-prec | |
1419 (capitalize (symbol-name calc-angle-mode)) | |
1420 (concat | |
1421 | |
1422 ;; Input-related modes | |
1423 (if (eq calc-algebraic-mode 'total) "Alg* " | |
1424 (if calc-algebraic-mode "Alg " | |
1425 (if calc-incomplete-algebraic-mode "Alg[( " ""))) | |
1426 | |
1427 ;; Computational modes | |
1428 (if calc-symbolic-mode "Symb " "") | |
1429 (cond ((eq calc-matrix-mode 'matrix) "Matrix ") | |
1430 ((integerp calc-matrix-mode) | |
1431 (format "Matrix%d " calc-matrix-mode)) | |
1432 ((eq calc-matrix-mode 'scalar) "Scalar ") | |
1433 (t "")) | |
1434 (if (eq calc-complex-mode 'polar) "Polar " "") | |
1435 (if calc-prefer-frac "Frac " "") | |
1436 (cond ((null calc-infinite-mode) "") | |
1437 ((eq calc-infinite-mode 1) "+Inf ") | |
1438 (t "Inf ")) | |
1439 (cond ((eq calc-simplify-mode 'none) "NoSimp ") | |
1440 ((eq calc-simplify-mode 'num) "NumSimp ") | |
1441 ((eq calc-simplify-mode 'binary) | |
1442 (format "BinSimp%d " calc-word-size)) | |
1443 ((eq calc-simplify-mode 'alg) "AlgSimp ") | |
1444 ((eq calc-simplify-mode 'ext) "ExtSimp ") | |
1445 ((eq calc-simplify-mode 'units) "UnitSimp ") | |
1446 (t "")) | |
1447 | |
1448 ;; Display modes | |
1449 (cond ((= calc-number-radix 10) "") | |
1450 ((= calc-number-radix 2) "Bin ") | |
1451 ((= calc-number-radix 8) "Oct ") | |
1452 ((= calc-number-radix 16) "Hex ") | |
1453 (t (format "Radix%d " calc-number-radix))) | |
1454 (if calc-leading-zeros "Zero " "") | |
1455 (cond ((null calc-language) "") | |
1456 ((eq calc-language 'tex) "TeX ") | |
1457 (t (concat | |
1458 (capitalize (symbol-name calc-language)) | |
1459 " "))) | |
1460 (cond ((eq fmt 'float) | |
1461 (if (zerop figs) "" (format "Norm%d " figs))) | |
1462 ((eq fmt 'fix) (format "Fix%d " figs)) | |
1463 ((eq fmt 'sci) | |
1464 (if (zerop figs) "Sci " (format "Sci%d " figs))) | |
1465 ((eq fmt 'eng) | |
1466 (if (zerop figs) "Eng " (format "Eng%d " figs)))) | |
1467 (cond ((not calc-display-just) | |
1468 (if calc-display-origin | |
1469 (format "Left%d " calc-display-origin) "")) | |
1470 ((eq calc-display-just 'right) | |
1471 (if calc-display-origin | |
1472 (format "Right%d " calc-display-origin) | |
1473 "Right ")) | |
1474 (t | |
1475 (if calc-display-origin | |
1476 (format "Center%d " calc-display-origin) | |
1477 "Center "))) | |
1478 (cond ((integerp calc-line-breaking) | |
1479 (format "Wid%d " calc-line-breaking)) | |
1480 (calc-line-breaking "") | |
1481 (t "Wide ")) | |
1482 | |
1483 ;; Miscellaneous other modes/indicators | |
1484 (if calc-assoc-selections "" "Break ") | |
1485 (cond ((eq calc-mode-save-mode 'save) "Save ") | |
1486 ((not calc-embedded-info) "") | |
1487 ((eq calc-mode-save-mode 'local) "Local ") | |
1488 ((eq calc-mode-save-mode 'edit) "LocEdit ") | |
1489 ((eq calc-mode-save-mode 'perm) "LocPerm ") | |
1490 ((eq calc-mode-save-mode 'global) "Global ") | |
1491 (t "")) | |
1492 (if calc-auto-recompute "" "Manual ") | |
1493 (if (and (fboundp 'calc-gnuplot-alive) | |
1494 (calc-gnuplot-alive)) "Graph " "") | |
1495 (if (and calc-embedded-info | |
1496 (> (calc-stack-size) 0) | |
1497 (calc-top 1 'sel)) "Sel " "") | |
1498 (if calc-display-dirty "Dirty " "") | |
1499 (if calc-inverse-flag "Inv " "") | |
1500 (if calc-hyperbolic-flag "Hyp " "") | |
1501 (if calc-keep-args-flag "Keep " "") | |
1502 (if (/= calc-stack-top 1) "Narrow " "") | |
1503 (apply 'concat calc-other-modes))))) | |
1504 (if (equal new-mode-string mode-line-buffer-identification) | |
1505 nil | |
1506 (setq mode-line-buffer-identification new-mode-string) | |
1507 (set-buffer-modified-p (buffer-modified-p)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1508 (and calc-embedded-info (calc-embedded-mode-line-change)))))) |
40785 | 1509 |
1510 (defun calc-align-stack-window () | |
1511 (if (eq major-mode 'calc-mode) | |
1512 (progn | |
1513 (let ((win (get-buffer-window (current-buffer)))) | |
1514 (if win | |
1515 (progn | |
1516 (calc-cursor-stack-index 0) | |
1517 (vertical-motion (- 2 (window-height win))) | |
1518 (set-window-start win (point))))) | |
1519 (calc-cursor-stack-index 0) | |
1520 (if (looking-at " *\\.$") | |
1521 (goto-char (1- (match-end 0))))) | |
1522 (save-excursion | |
1523 (calc-select-buffer) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1524 (calc-align-stack-window)))) |
40785 | 1525 |
1526 (defun calc-check-stack (n) | |
1527 (if (> n (calc-stack-size)) | |
1528 (error "Too few elements on stack")) | |
1529 (if (< n 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1530 (error "Invalid argument"))) |
40785 | 1531 |
1532 (defun calc-push-list (vals &optional m sels) | |
1533 (while vals | |
1534 (if calc-executing-macro | |
1535 (calc-push-list-in-macro vals m sels) | |
1536 (save-excursion | |
1537 (calc-select-buffer) | |
1538 (let* ((val (car vals)) | |
1539 (entry (list val 1 (car sels))) | |
1540 (mm (+ (or m 1) calc-stack-top))) | |
1541 (calc-cursor-stack-index (1- (or m 1))) | |
1542 (if (> mm 1) | |
1543 (setcdr (nthcdr (- mm 2) calc-stack) | |
1544 (cons entry (nthcdr (1- mm) calc-stack))) | |
1545 (setq calc-stack (cons entry calc-stack))) | |
1546 (let ((buffer-read-only nil)) | |
1547 (insert (math-format-stack-value entry) "\n")) | |
1548 (calc-record-undo (list 'push mm)) | |
1549 (calc-set-command-flag 'renum-stack)))) | |
1550 (setq vals (cdr vals) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1551 sels (cdr sels)))) |
40785 | 1552 |
1553 (defun calc-pop-push-list (n vals &optional m sels) | |
1554 (if (and calc-any-selections (null sels)) | |
1555 (calc-replace-selections n vals m) | |
1556 (calc-pop-stack n m sels) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1557 (calc-push-list vals m sels))) |
40785 | 1558 |
1559 (defun calc-pop-push-record-list (n prefix vals &optional m sels) | |
1560 (or (and (consp vals) | |
1561 (or (integerp (car vals)) | |
1562 (consp (car vals)))) | |
1563 (and vals (setq vals (list vals) | |
1564 sels (and sels (list sels))))) | |
1565 (calc-check-stack (+ n (or m 1) -1)) | |
1566 (if prefix | |
1567 (if (cdr vals) | |
1568 (calc-record-list vals prefix) | |
1569 (calc-record (car vals) prefix))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1570 (calc-pop-push-list n vals m sels)) |
40785 | 1571 |
1572 (defun calc-enter-result (n prefix vals &optional m) | |
1573 (setq calc-aborted-prefix prefix) | |
1574 (if (and (consp vals) | |
1575 (or (integerp (car vals)) | |
1576 (consp (car vals)))) | |
1577 (setq vals (mapcar 'calc-normalize vals)) | |
1578 (setq vals (calc-normalize vals))) | |
1579 (or (and (consp vals) | |
1580 (or (integerp (car vals)) | |
1581 (consp (car vals)))) | |
1582 (setq vals (list vals))) | |
1583 (if (equal vals '((nil))) | |
1584 (setq vals nil)) | |
1585 (calc-pop-push-record-list n prefix vals m) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1586 (calc-handle-whys)) |
40785 | 1587 |
1588 (defun calc-normalize (val) | |
1589 (if (memq calc-simplify-mode '(nil none num)) | |
1590 (math-normalize val) | |
1591 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1592 (calc-normalize-fancy val))) |
40785 | 1593 |
1594 (defun calc-handle-whys () | |
1595 (if calc-next-why | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1596 (calc-do-handle-whys))) |
40785 | 1597 |
1598 | |
1599 (defun calc-pop-stack (&optional n m sel-ok) ; pop N objs at level M of stack. | |
1600 (or n (setq n 1)) | |
1601 (or m (setq m 1)) | |
1602 (or calc-keep-args-flag | |
1603 (let ((mm (+ m calc-stack-top))) | |
1604 (if (and calc-any-selections (not sel-ok) | |
1605 (calc-top-selected n m)) | |
1606 (calc-sel-error)) | |
1607 (if calc-executing-macro | |
1608 (calc-pop-stack-in-macro n mm) | |
1609 (calc-record-undo (list 'pop mm (calc-top-list n m 'full))) | |
1610 (save-excursion | |
1611 (calc-select-buffer) | |
1612 (let ((buffer-read-only nil)) | |
1613 (if (> mm 1) | |
1614 (progn | |
1615 (calc-cursor-stack-index (1- m)) | |
1616 (let ((bot (point))) | |
1617 (calc-cursor-stack-index (+ n m -1)) | |
1618 (delete-region (point) bot)) | |
1619 (setcdr (nthcdr (- mm 2) calc-stack) | |
1620 (nthcdr (+ n mm -1) calc-stack))) | |
1621 (calc-cursor-stack-index n) | |
1622 (setq calc-stack (nthcdr n calc-stack)) | |
1623 (delete-region (point) (point-max)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1624 (calc-set-command-flag 'renum-stack)))))) |
40785 | 1625 |
1626 (defun calc-get-stack-element (x) | |
1627 (cond ((eq sel-mode 'entry) | |
1628 x) | |
1629 ((eq sel-mode 'sel) | |
1630 (nth 2 x)) | |
1631 ((or (null (nth 2 x)) | |
1632 (eq sel-mode 'full) | |
1633 (not calc-use-selections)) | |
1634 (car x)) | |
1635 (sel-mode | |
1636 (calc-sel-error)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1637 (t (nth 2 x)))) |
40785 | 1638 |
1639 ;; Get the Nth element of the stack (N=1 is the top element). | |
1640 (defun calc-top (&optional n sel-mode) | |
1641 (or n (setq n 1)) | |
1642 (calc-check-stack n) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1643 (calc-get-stack-element (nth (+ n calc-stack-top -1) calc-stack))) |
40785 | 1644 |
1645 (defun calc-top-n (&optional n sel-mode) ; in case precision has changed | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1646 (math-check-complete (calc-normalize (calc-top n sel-mode)))) |
40785 | 1647 |
1648 (defun calc-top-list (&optional n m sel-mode) | |
1649 (or n (setq n 1)) | |
1650 (or m (setq m 1)) | |
1651 (calc-check-stack (+ n m -1)) | |
1652 (and (> n 0) | |
1653 (let ((top (copy-sequence (nthcdr (+ m calc-stack-top -1) | |
1654 calc-stack)))) | |
1655 (setcdr (nthcdr (1- n) top) nil) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1656 (nreverse (mapcar 'calc-get-stack-element top))))) |
40785 | 1657 |
1658 (defun calc-top-list-n (&optional n m sel-mode) | |
1659 (mapcar 'math-check-complete | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1660 (mapcar 'calc-normalize (calc-top-list n m sel-mode)))) |
40785 | 1661 |
1662 | |
1663 (defun calc-renumber-stack () | |
1664 (if calc-line-numbering | |
1665 (save-excursion | |
1666 (calc-cursor-stack-index 0) | |
1667 (let ((lnum 1) | |
1668 (buffer-read-only nil) | |
1669 (stack (nthcdr calc-stack-top calc-stack))) | |
1670 (if (re-search-forward "^[0-9]+[:*]" nil t) | |
1671 (progn | |
1672 (beginning-of-line) | |
1673 (while (re-search-forward "^[0-9]+[:*]" nil t) | |
1674 (let ((buffer-read-only nil)) | |
1675 (beginning-of-line) | |
1676 (delete-char 4) | |
1677 (insert " "))) | |
1678 (calc-cursor-stack-index 0))) | |
1679 (while (re-search-backward "^[0-9]+[:*]" nil t) | |
1680 (delete-char 4) | |
1681 (if (> lnum 999) | |
1682 (insert (format "%03d%s" (% lnum 1000) | |
1683 (if (and (nth 2 (car stack)) | |
1684 calc-use-selections) "*" ":"))) | |
1685 (let ((prefix (int-to-string lnum))) | |
1686 (insert prefix (if (and (nth 2 (car stack)) | |
1687 calc-use-selections) "*" ":") | |
1688 (make-string (- 3 (length prefix)) 32)))) | |
1689 (beginning-of-line) | |
1690 (setq lnum (1+ lnum) | |
1691 stack (cdr stack)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1692 (and calc-embedded-info (calc-embedded-stack-change))) |
40785 | 1693 |
1694 (defun calc-refresh (&optional align) | |
1695 (interactive) | |
1696 (and (eq major-mode 'calc-mode) | |
1697 (not calc-executing-macro) | |
1698 (let* ((buffer-read-only nil) | |
1699 (save-point (point)) | |
1700 (save-mark (condition-case err (mark) (error nil))) | |
1701 (save-aligned (looking-at "\\.$")) | |
1702 (thing calc-stack)) | |
1703 (setq calc-any-selections nil | |
1704 calc-any-evaltos nil) | |
1705 (erase-buffer) | |
45578
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
1706 (when calc-show-banner |
45769 | 1707 (insert (propertize "--- Emacs Calculator Mode ---\n" |
1708 'font-lock-face 'italic))) | |
40785 | 1709 (while thing |
1710 (goto-char (point-min)) | |
45578
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
1711 (when calc-show-banner |
73f6b3b88ae9
(calc-show-banner): New variable.
Miles Bader <miles@gnu.org>
parents:
44574
diff
changeset
|
1712 (forward-line 1)) |
40785 | 1713 (insert (math-format-stack-value (car thing)) "\n") |
1714 (setq thing (cdr thing))) | |
1715 (calc-renumber-stack) | |
1716 (if calc-display-dirty | |
1717 (calc-wrapper (setq calc-display-dirty nil))) | |
1718 (and calc-any-evaltos calc-auto-recompute | |
1719 (calc-wrapper (calc-refresh-evaltos))) | |
1720 (if (or align save-aligned) | |
1721 (calc-align-stack-window) | |
1722 (goto-char save-point)) | |
1723 (if save-mark (set-mark save-mark)))) | |
1724 (and calc-embedded-info (not (eq major-mode 'calc-mode)) | |
1725 (save-excursion | |
1726 (set-buffer (aref calc-embedded-info 1)) | |
1727 (calc-refresh align))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1728 (setq calc-refresh-count (1+ calc-refresh-count))) |
40785 | 1729 |
1730 | |
1731 (defun calc-x-paste-text (arg) | |
1732 "Move point to mouse position and insert window system cut buffer contents. | |
1733 If mouse is pressed in Calc window, push cut buffer contents onto the stack." | |
1734 (x-mouse-select arg) | |
1735 (if (memq major-mode '(calc-mode calc-trail-mode)) | |
1736 (progn | |
1737 (calc-wrapper | |
1738 (calc-extensions) | |
1739 (let* ((buf (x-get-cut-buffer)) | |
1740 (val (math-read-exprs (calc-clean-newlines buf)))) | |
1741 (if (eq (car-safe val) 'error) | |
1742 (progn | |
1743 (setq val (math-read-exprs buf)) | |
1744 (if (eq (car-safe val) 'error) | |
1745 (error "%s in yanked data" (nth 2 val))))) | |
1746 (calc-enter-result 0 "Xynk" val)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1747 (x-paste-text arg))) |
40785 | 1748 |
1749 | |
1750 | |
1751 ;;;; The Calc Trail buffer. | |
1752 | |
1753 (defun calc-check-trail-aligned () | |
1754 (save-excursion | |
1755 (let ((win (get-buffer-window (current-buffer)))) | |
1756 (and win | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1757 (pos-visible-in-window-p (1- (point-max)) win))))) |
40785 | 1758 |
1759 (defun calc-trail-buffer () | |
1760 (and (or (null calc-trail-buffer) | |
1761 (null (buffer-name calc-trail-buffer))) | |
1762 (save-excursion | |
1763 (setq calc-trail-buffer (get-buffer-create "*Calc Trail*")) | |
1764 (let ((buf (or (and (not (eq major-mode 'calc-mode)) | |
1765 (get-buffer "*Calculator*")) | |
1766 (current-buffer)))) | |
1767 (set-buffer calc-trail-buffer) | |
1768 (or (eq major-mode 'calc-trail-mode) | |
1769 (calc-trail-mode buf))))) | |
1770 (or (and calc-trail-pointer | |
1771 (eq (marker-buffer calc-trail-pointer) calc-trail-buffer)) | |
1772 (save-excursion | |
1773 (set-buffer calc-trail-buffer) | |
1774 (goto-line 2) | |
1775 (setq calc-trail-pointer (point-marker)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1776 calc-trail-buffer) |
40785 | 1777 |
1778 (defun calc-record (val &optional prefix) | |
1779 (setq calc-aborted-prefix nil) | |
1780 (or calc-executing-macro | |
1781 (let* ((mainbuf (current-buffer)) | |
1782 (buf (calc-trail-buffer)) | |
1783 (calc-display-raw nil) | |
1784 (calc-can-abbrev-vectors t) | |
1785 (fval (if val | |
1786 (if (stringp val) | |
1787 val | |
1788 (math-showing-full-precision | |
1789 (math-format-flat-expr val 0))) | |
1790 ""))) | |
1791 (save-excursion | |
1792 (set-buffer buf) | |
1793 (let ((aligned (calc-check-trail-aligned)) | |
1794 (buffer-read-only nil)) | |
1795 (goto-char (point-max)) | |
1796 (cond ((null prefix) (insert " ")) | |
1797 ((and (> (length prefix) 4) | |
1798 (string-match " " prefix 4)) | |
1799 (insert (substring prefix 0 4) " ")) | |
1800 (t (insert (format "%4s " prefix)))) | |
1801 (insert fval "\n") | |
1802 (let ((win (get-buffer-window buf))) | |
1803 (if (and aligned win (not (memq 'hold-trail calc-command-flags))) | |
1804 (calc-trail-here)) | |
1805 (goto-char (1- (point-max)))))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1806 val) |
40785 | 1807 |
1808 | |
1809 (defun calc-trail-display (flag &optional no-refresh) | |
1810 (interactive "P") | |
1811 (let ((win (get-buffer-window (calc-trail-buffer)))) | |
1812 (if (setq calc-display-trail | |
1813 (not (if flag (memq flag '(nil 0)) win))) | |
1814 (if (null win) | |
1815 (progn | |
1816 (if (and (boundp 'calc-trail-window-hook) calc-trail-window-hook) | |
1817 (run-hooks 'calc-trail-window-hook) | |
1818 (let ((w (split-window nil (/ (* (window-width) 2) 3) t))) | |
1819 (set-window-buffer w calc-trail-buffer))) | |
1820 (calc-wrapper | |
1821 (setq overlay-arrow-string calc-trail-overlay | |
1822 overlay-arrow-position calc-trail-pointer) | |
1823 (or no-refresh | |
1824 (if (interactive-p) | |
1825 (calc-do-refresh) | |
1826 (calc-refresh)))))) | |
1827 (if win | |
1828 (progn | |
1829 (delete-window win) | |
1830 (calc-wrapper | |
1831 (or no-refresh | |
1832 (if (interactive-p) | |
1833 (calc-do-refresh) | |
1834 (calc-refresh)))))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1835 calc-trail-buffer) |
40785 | 1836 |
1837 (defun calc-trail-here () | |
1838 (interactive) | |
1839 (if (eq major-mode 'calc-trail-mode) | |
1840 (progn | |
1841 (beginning-of-line) | |
1842 (if (bobp) | |
1843 (forward-line 1) | |
1844 (if (eobp) | |
1845 (forward-line -1))) | |
1846 (if (or (bobp) (eobp)) | |
1847 (setq overlay-arrow-position nil) ; trail is empty | |
1848 (set-marker calc-trail-pointer (point) (current-buffer)) | |
1849 (setq calc-trail-overlay (concat (buffer-substring (point) | |
1850 (+ (point) 4)) | |
1851 ">") | |
1852 overlay-arrow-string calc-trail-overlay | |
1853 overlay-arrow-position calc-trail-pointer) | |
1854 (forward-char 4) | |
1855 (let ((win (get-buffer-window (current-buffer)))) | |
1856 (if win | |
1857 (save-excursion | |
1858 (forward-line (/ (window-height win) 2)) | |
1859 (forward-line (- 1 (window-height win))) | |
1860 (set-window-start win (point)) | |
1861 (set-window-point win (+ calc-trail-pointer 4)) | |
1862 (set-buffer calc-main-buffer) | |
1863 (setq overlay-arrow-string calc-trail-overlay | |
1864 overlay-arrow-position calc-trail-pointer)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1865 (error "Not in Calc Trail buffer"))) |
40785 | 1866 |
1867 | |
1868 | |
1869 | |
1870 ;;;; The Undo list. | |
1871 | |
1872 (defun calc-record-undo (rec) | |
1873 (or calc-executing-macro | |
1874 (if (memq 'undo calc-command-flags) | |
1875 (setq calc-undo-list (cons (cons rec (car calc-undo-list)) | |
1876 (cdr calc-undo-list))) | |
1877 (setq calc-undo-list (cons (list rec) calc-undo-list) | |
1878 calc-redo-list nil) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1879 (calc-set-command-flag 'undo)))) |
40785 | 1880 |
1881 | |
1882 | |
1883 | |
1884 ;;; Arithmetic commands. | |
1885 | |
1886 (defun calc-binary-op (name func arg &optional ident unary func2) | |
1887 (setq calc-aborted-prefix name) | |
1888 (if (null arg) | |
1889 (calc-enter-result 2 name (cons (or func2 func) | |
1890 (mapcar 'math-check-complete | |
1891 (calc-top-list 2)))) | |
1892 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1893 (calc-binary-op-fancy name func arg ident unary))) |
40785 | 1894 |
1895 (defun calc-unary-op (name func arg &optional func2) | |
1896 (setq calc-aborted-prefix name) | |
1897 (if (null arg) | |
1898 (calc-enter-result 1 name (list (or func2 func) | |
1899 (math-check-complete (calc-top 1)))) | |
1900 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1901 (calc-unary-op-fancy name func arg))) |
40785 | 1902 |
1903 | |
1904 (defun calc-plus (arg) | |
1905 (interactive "P") | |
1906 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1907 (calc-binary-op "+" 'calcFunc-add arg 0 nil '+))) |
40785 | 1908 |
1909 (defun calc-minus (arg) | |
1910 (interactive "P") | |
1911 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1912 (calc-binary-op "-" 'calcFunc-sub arg 0 'neg '-))) |
40785 | 1913 |
1914 (defun calc-times (arg) | |
1915 (interactive "P") | |
1916 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1917 (calc-binary-op "*" 'calcFunc-mul arg 1 nil '*))) |
40785 | 1918 |
1919 (defun calc-divide (arg) | |
1920 (interactive "P") | |
1921 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1922 (calc-binary-op "/" 'calcFunc-div arg 0 'calcFunc-inv '/))) |
40785 | 1923 |
1924 | |
1925 (defun calc-change-sign (arg) | |
1926 (interactive "P") | |
1927 (calc-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1928 (calc-unary-op "chs" 'neg arg))) |
40785 | 1929 |
1930 | |
1931 | |
1932 ;;; Stack management commands. | |
1933 | |
1934 (defun calc-enter (n) | |
1935 (interactive "p") | |
1936 (calc-wrapper | |
1937 (cond ((< n 0) | |
1938 (calc-push-list (calc-top-list 1 (- n)))) | |
1939 ((= n 0) | |
1940 (calc-push-list (calc-top-list (calc-stack-size)))) | |
1941 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1942 (calc-push-list (calc-top-list n)))))) |
40785 | 1943 |
1944 | |
1945 (defun calc-pop (n) | |
1946 (interactive "P") | |
1947 (calc-wrapper | |
1948 (let* ((nn (prefix-numeric-value n)) | |
1949 (top (and (null n) (calc-top 1)))) | |
1950 (cond ((and (null n) | |
1951 (eq (car-safe top) 'incomplete) | |
1952 (> (length top) (if (eq (nth 1 top) 'intv) 3 2))) | |
1953 (calc-pop-push-list 1 (let ((tt (copy-sequence top))) | |
1954 (setcdr (nthcdr (- (length tt) 2) tt) nil) | |
1955 (list tt)))) | |
1956 ((< nn 0) | |
1957 (if (and calc-any-selections | |
1958 (calc-top-selected 1 (- nn))) | |
1959 (calc-delete-selection (- nn)) | |
1960 (calc-pop-stack 1 (- nn) t))) | |
1961 ((= nn 0) | |
1962 (calc-pop-stack (calc-stack-size) 1 t)) | |
1963 (t | |
1964 (if (and calc-any-selections | |
1965 (= nn 1) | |
1966 (calc-top-selected 1 1)) | |
1967 (calc-delete-selection 1) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
1968 (calc-pop-stack nn))))))) |
40785 | 1969 |
1970 | |
1971 | |
1972 | |
1973 ;;;; Reading a number using the minibuffer. | |
1974 | |
1975 (defun calcDigit-start () | |
1976 (interactive) | |
1977 (calc-wrapper | |
1978 (if (or calc-algebraic-mode | |
1979 (and (> calc-number-radix 14) (eq last-command-char ?e))) | |
1980 (calc-alg-digit-entry) | |
1981 (calc-unread-command) | |
1982 (setq calc-aborted-prefix nil) | |
1983 (let* ((calc-digit-value nil) | |
1984 (calc-prev-char nil) | |
1985 (calc-prev-prev-char nil) | |
1986 (calc-buffer (current-buffer)) | |
1987 (buf (if calc-emacs-type-lucid | |
1988 (catch 'calc-foo | |
1989 (catch 'execute-kbd-macro | |
1990 (throw 'calc-foo | |
1991 (read-from-minibuffer | |
1992 "Calc: " "" calc-digit-map))) | |
1993 (error "Lucid Emacs requires RET after %s" | |
1994 "digit entry in kbd macro")) | |
1995 (let ((old-esc (lookup-key global-map "\e"))) | |
1996 (unwind-protect | |
1997 (progn | |
1998 (define-key global-map "\e" nil) | |
1999 (read-from-minibuffer "Calc: " "" calc-digit-map)) | |
2000 (define-key global-map "\e" old-esc)))))) | |
2001 (or calc-digit-value (setq calc-digit-value (math-read-number buf))) | |
2002 (if (stringp calc-digit-value) | |
2003 (calc-alg-entry calc-digit-value) | |
2004 (if calc-digit-value | |
2005 (calc-push-list (list (calc-record (calc-normalize | |
2006 calc-digit-value)))))) | |
2007 (if (eq calc-prev-char 'dots) | |
2008 (progn | |
2009 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2010 (calc-dots))))))) |
40785 | 2011 |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2012 (defsubst calc-minibuffer-size () |
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2013 (- (point-max) (minibuffer-prompt-end))) |
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2014 |
40785 | 2015 (defun calcDigit-nondigit () |
2016 (interactive) | |
2017 ;; Exercise for the reader: Figure out why this is a good precaution! | |
2018 (or (boundp 'calc-buffer) | |
2019 (use-local-map minibuffer-local-map)) | |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2020 (let ((str (minibuffer-contents))) |
40785 | 2021 (setq calc-digit-value (save-excursion |
2022 (set-buffer calc-buffer) | |
2023 (math-read-number str)))) | |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2024 (if (and (null calc-digit-value) (> (calc-minibuffer-size) 0)) |
40785 | 2025 (progn |
2026 (beep) | |
2027 (calc-temp-minibuffer-message " [Bad format]")) | |
2028 (or (memq last-command-char '(32 13)) | |
2029 (progn (setq prefix-arg current-prefix-arg) | |
2030 (calc-unread-command (if (and (eq last-command-char 27) | |
2031 (>= last-input-char 128)) | |
2032 last-input-char | |
2033 nil)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2034 (exit-minibuffer))) |
40785 | 2035 |
2036 | |
2037 (defun calc-minibuffer-contains (rex) | |
2038 (save-excursion | |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2039 (goto-char (minibuffer-prompt-end)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2040 (looking-at rex))) |
40785 | 2041 |
2042 (defun calcDigit-key () | |
2043 (interactive) | |
2044 (goto-char (point-max)) | |
2045 (if (or (and (memq last-command-char '(?+ ?-)) | |
2046 (> (buffer-size) 0) | |
2047 (/= (preceding-char) ?e)) | |
2048 (and (memq last-command-char '(?m ?s)) | |
2049 (not (calc-minibuffer-contains "[-+]?[0-9]+\\.?0*[@oh].*")) | |
2050 (not (calc-minibuffer-contains "[-+]?\\(1[1-9]\\|[2-9][0-9]\\)#.*")))) | |
2051 (calcDigit-nondigit) | |
2052 (if (calc-minibuffer-contains "\\([-+]?\\|.* \\)\\'") | |
2053 (cond ((memq last-command-char '(?. ?@)) (insert "0")) | |
2054 ((and (memq last-command-char '(?o ?h ?m)) | |
2055 (not (calc-minibuffer-contains ".*#.*"))) (insert "0")) | |
2056 ((memq last-command-char '(?: ?e)) (insert "1")) | |
2057 ((eq last-command-char ?#) | |
2058 (insert (int-to-string calc-number-radix))))) | |
2059 (if (and (calc-minibuffer-contains "\\([-+]?[0-9]+#\\|[^:]*:\\)\\'") | |
2060 (eq last-command-char ?:)) | |
2061 (insert "1")) | |
2062 (if (and (calc-minibuffer-contains "[-+]?[0-9]+#\\'") | |
2063 (eq last-command-char ?.)) | |
2064 (insert "0")) | |
2065 (if (and (calc-minibuffer-contains "[-+]?0*\\([2-9]\\|1[0-4]\\)#\\'") | |
2066 (eq last-command-char ?e)) | |
2067 (insert "1")) | |
2068 (if (or (and (memq last-command-char '(?h ?o ?m ?s ?p)) | |
2069 (calc-minibuffer-contains ".*#.*")) | |
2070 (and (eq last-command-char ?e) | |
2071 (calc-minibuffer-contains "[-+]?\\(1[5-9]\\|[2-9][0-9]\\)#.*")) | |
2072 (and (eq last-command-char ?n) | |
2073 (calc-minibuffer-contains "[-+]?\\(2[4-9]\\|[3-9][0-9]\\)#.*"))) | |
2074 (setq last-command-char (upcase last-command-char))) | |
2075 (cond | |
2076 ((memq last-command-char '(?_ ?n)) | |
43185
e38061462de6
(calcDigit-key): Use minibuffer-prompt-end instead of point-min.
Andreas Schwab <schwab@suse.de>
parents:
42205
diff
changeset
|
2077 (goto-char (minibuffer-prompt-end)) |
40785 | 2078 (if (and (search-forward " +/- " nil t) |
2079 (not (search-forward "e" nil t))) | |
2080 (beep) | |
2081 (and (not (calc-minibuffer-contains "[-+]?\\(1[5-9]\\|[2-9][0-9]\\)#.*")) | |
2082 (search-forward "e" nil t)) | |
2083 (if (looking-at "+") | |
2084 (delete-char 1)) | |
2085 (if (looking-at "-") | |
2086 (delete-char 1) | |
2087 (insert "-"))) | |
2088 (goto-char (point-max))) | |
2089 ((eq last-command-char ?p) | |
2090 (if (or (calc-minibuffer-contains ".*\\+/-.*") | |
2091 (calc-minibuffer-contains ".*mod.*") | |
2092 (calc-minibuffer-contains ".*#.*") | |
2093 (calc-minibuffer-contains ".*[-+e:]\\'")) | |
2094 (beep) | |
2095 (if (not (calc-minibuffer-contains ".* \\'")) | |
2096 (insert " ")) | |
2097 (insert "+/- "))) | |
2098 ((and (eq last-command-char ?M) | |
2099 (not (calc-minibuffer-contains | |
2100 "[-+]?\\(2[3-9]\\|[3-9][0-9]\\)#.*"))) | |
2101 (if (or (calc-minibuffer-contains ".*\\+/-.*") | |
2102 (calc-minibuffer-contains ".*mod *[^ ]+") | |
2103 (calc-minibuffer-contains ".*[-+e:]\\'")) | |
2104 (beep) | |
2105 (if (calc-minibuffer-contains ".*mod \\'") | |
2106 (if calc-previous-modulo | |
2107 (insert (math-format-flat-expr calc-previous-modulo 0)) | |
2108 (beep)) | |
2109 (if (not (calc-minibuffer-contains ".* \\'")) | |
2110 (insert " ")) | |
2111 (insert "mod ")))) | |
2112 (t | |
2113 (insert (char-to-string last-command-char)) | |
2114 (if (or (and (calc-minibuffer-contains "[-+]?\\(.*\\+/- *\\|.*mod *\\)?\\([0-9][0-9]?\\)#[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\)?\\|.[0-9a-zA-Z]*\\(e[-+]?[0-9]*\\)?\\)?\\'") | |
2115 (let ((radix (string-to-int | |
2116 (buffer-substring | |
2117 (match-beginning 2) (match-end 2))))) | |
2118 (and (>= radix 2) | |
2119 (<= radix 36) | |
2120 (or (memq last-command-char '(?# ?: ?. ?e ?+ ?-)) | |
2121 (let ((dig (math-read-radix-digit | |
2122 (upcase last-command-char)))) | |
2123 (and dig | |
2124 (< dig radix))))))) | |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2125 (calc-minibuffer-contains |
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2126 "[-+]?\\(.*\\+/- *\\|.*mod *\\)?\\([0-9]+\\.?0*[@oh] *\\)?\\([0-9]+\\.?0*['m] *\\)?[0-9]*\\(\\.?[0-9]*\\(e[-+]?[0-3]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?\\)?\\|[0-9]:\\([0-9]+:\\)?[0-9]*\\)?[\"s]?\\'")) |
40785 | 2127 (if (and (memq last-command-char '(?@ ?o ?h ?\' ?m)) |
2128 (string-match " " calc-hms-format)) | |
2129 (insert " ")) | |
2130 (if (and (eq this-command last-command) | |
2131 (eq last-command-char ?.)) | |
2132 (progn | |
2133 (calc-extensions) | |
2134 (calc-digit-dots)) | |
2135 (delete-backward-char 1) | |
2136 (beep) | |
2137 (calc-temp-minibuffer-message " [Bad format]")))))) | |
2138 (setq calc-prev-prev-char calc-prev-char | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2139 calc-prev-char last-command-char)) |
40785 | 2140 |
2141 | |
2142 (defun calcDigit-backspace () | |
2143 (interactive) | |
2144 (goto-char (point-max)) | |
2145 (cond ((calc-minibuffer-contains ".* \\+/- \\'") | |
2146 (backward-delete-char 5)) | |
2147 ((calc-minibuffer-contains ".* mod \\'") | |
2148 (backward-delete-char 5)) | |
2149 ((calc-minibuffer-contains ".* \\'") | |
2150 (backward-delete-char 2)) | |
2151 ((eq last-command 'calcDigit-start) | |
2152 (erase-buffer)) | |
2153 (t (backward-delete-char 1))) | |
40911
df97a382ad43
(toplevel): Require calc-macs.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2154 (if (= (calc-minibuffer-size) 0) |
40785 | 2155 (progn |
2156 (setq last-command-char 13) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2157 (calcDigit-nondigit)))) |
40785 | 2158 |
2159 | |
2160 | |
2161 | |
2162 | |
2163 | |
2164 | |
2165 ;;;; Arithmetic routines. | |
2166 ;;; | |
2167 ;;; An object as manipulated by one of these routines may take any of the | |
2168 ;;; following forms: | |
2169 ;;; | |
2170 ;;; integer An integer. For normalized numbers, this format | |
2171 ;;; is used only for -999999 ... 999999. | |
2172 ;;; | |
2173 ;;; (bigpos N0 N1 N2 ...) A big positive integer, N0 + N1*1000 + N2*10^6 ... | |
2174 ;;; (bigneg N0 N1 N2 ...) A big negative integer, - N0 - N1*1000 ... | |
2175 ;;; Each digit N is in the range 0 ... 999. | |
2176 ;;; Normalized, always at least three N present, | |
2177 ;;; and the most significant N is nonzero. | |
2178 ;;; | |
2179 ;;; (frac NUM DEN) A fraction. NUM and DEN are small or big integers. | |
2180 ;;; Normalized, DEN > 1. | |
2181 ;;; | |
2182 ;;; (float NUM EXP) A floating-point number, NUM * 10^EXP; | |
2183 ;;; NUM is a small or big integer, EXP is a small int. | |
2184 ;;; Normalized, NUM is not a multiple of 10, and | |
2185 ;;; abs(NUM) < 10^calc-internal-prec. | |
2186 ;;; Normalized zero is stored as (float 0 0). | |
2187 ;;; | |
2188 ;;; (cplx REAL IMAG) A complex number; REAL and IMAG are any of above. | |
2189 ;;; Normalized, IMAG is nonzero. | |
2190 ;;; | |
2191 ;;; (polar R THETA) Polar complex number. Normalized, R > 0 and THETA | |
2192 ;;; is neither zero nor 180 degrees (pi radians). | |
2193 ;;; | |
2194 ;;; (vec A B C ...) Vector of objects A, B, C, ... A matrix is a | |
2195 ;;; vector of vectors. | |
2196 ;;; | |
2197 ;;; (hms H M S) Angle in hours-minutes-seconds form. All three | |
2198 ;;; components have the same sign; H and M must be | |
2199 ;;; numerically integers; M and S are expected to | |
2200 ;;; lie in the range [0,60). | |
2201 ;;; | |
2202 ;;; (date N) A date or date/time object. N is an integer to | |
2203 ;;; store a date only, or a fraction or float to | |
2204 ;;; store a date and time. | |
2205 ;;; | |
2206 ;;; (sdev X SIGMA) Error form, X +/- SIGMA. When normalized, | |
2207 ;;; SIGMA > 0. X is any complex number and SIGMA | |
2208 ;;; is real numbers; or these may be symbolic | |
2209 ;;; expressions where SIGMA is assumed real. | |
2210 ;;; | |
2211 ;;; (intv MASK LO HI) Interval form. MASK is 0=(), 1=(], 2=[), or 3=[]. | |
2212 ;;; LO and HI are any real numbers, or symbolic | |
2213 ;;; expressions which are assumed real, and LO < HI. | |
2214 ;;; For [LO..HI], if LO = HI normalization produces LO, | |
2215 ;;; and if LO > HI normalization produces [LO..LO). | |
2216 ;;; For other intervals, if LO > HI normalization | |
2217 ;;; sets HI equal to LO. | |
2218 ;;; | |
2219 ;;; (mod N M) Number modulo M. When normalized, 0 <= N < M. | |
2220 ;;; N and M are real numbers. | |
2221 ;;; | |
2222 ;;; (var V S) Symbolic variable. V is a Lisp symbol which | |
2223 ;;; represents the variable's visible name. S is | |
2224 ;;; the symbol which actually stores the variable's | |
2225 ;;; value: (var pi var-pi). | |
2226 ;;; | |
2227 ;;; In general, combining rational numbers in a calculation always produces | |
2228 ;;; a rational result, but if either argument is a float, result is a float. | |
2229 | |
2230 ;;; In the following comments, [x y z] means result is x, args must be y, z, | |
2231 ;;; respectively, where the code letters are: | |
2232 ;;; | |
2233 ;;; O Normalized object (vector or number) | |
2234 ;;; V Normalized vector | |
2235 ;;; N Normalized number of any type | |
2236 ;;; N Normalized complex number | |
2237 ;;; R Normalized real number (float or rational) | |
2238 ;;; F Normalized floating-point number | |
2239 ;;; T Normalized rational number | |
2240 ;;; I Normalized integer | |
2241 ;;; B Normalized big integer | |
2242 ;;; S Normalized small integer | |
2243 ;;; D Digit (small integer, 0..999) | |
2244 ;;; L Normalized bignum digit list (without "bigpos" or "bigneg" symbol) | |
2245 ;;; or normalized vector element list (without "vec") | |
2246 ;;; P Predicate (truth value) | |
2247 ;;; X Any Lisp object | |
2248 ;;; Z "nil" | |
2249 ;;; | |
2250 ;;; Lower-case letters signify possibly un-normalized values. | |
2251 ;;; "L.D" means a cons of an L and a D. | |
2252 ;;; [N N; n n] means result will be normalized if argument is. | |
2253 ;;; Also, [Public] marks routines intended to be called from outside. | |
2254 ;;; [This notation has been neglected in many recent routines.] | |
2255 | |
2256 ;;; Reduce an object to canonical (normalized) form. [O o; Z Z] [Public] | |
2257 (defun math-normalize (a) | |
2258 (cond | |
2259 ((not (consp a)) | |
2260 (if (integerp a) | |
2261 (if (or (>= a 1000000) (<= a -1000000)) | |
2262 (math-bignum a) | |
2263 a) | |
2264 a)) | |
2265 ((eq (car a) 'bigpos) | |
2266 (if (eq (nth (1- (length a)) a) 0) | |
2267 (let* ((last (setq a (copy-sequence a))) (digs a)) | |
2268 (while (setq digs (cdr digs)) | |
2269 (or (eq (car digs) 0) (setq last digs))) | |
2270 (setcdr last nil))) | |
2271 (if (cdr (cdr (cdr a))) | |
2272 a | |
2273 (cond | |
2274 ((cdr (cdr a)) (+ (nth 1 a) (* (nth 2 a) 1000))) | |
2275 ((cdr a) (nth 1 a)) | |
2276 (t 0)))) | |
2277 ((eq (car a) 'bigneg) | |
2278 (if (eq (nth (1- (length a)) a) 0) | |
2279 (let* ((last (setq a (copy-sequence a))) (digs a)) | |
2280 (while (setq digs (cdr digs)) | |
2281 (or (eq (car digs) 0) (setq last digs))) | |
2282 (setcdr last nil))) | |
2283 (if (cdr (cdr (cdr a))) | |
2284 a | |
2285 (cond | |
2286 ((cdr (cdr a)) (- (+ (nth 1 a) (* (nth 2 a) 1000)))) | |
2287 ((cdr a) (- (nth 1 a))) | |
2288 (t 0)))) | |
2289 ((eq (car a) 'float) | |
2290 (math-make-float (math-normalize (nth 1 a)) (nth 2 a))) | |
2291 ((or (memq (car a) '(frac cplx polar hms date mod sdev intv vec var quote | |
2292 special-const calcFunc-if calcFunc-lambda | |
2293 calcFunc-quote calcFunc-condition | |
2294 calcFunc-evalto)) | |
2295 (integerp (car a)) | |
2296 (and (consp (car a)) (not (eq (car (car a)) 'lambda)))) | |
2297 (calc-extensions) | |
2298 (math-normalize-fancy a)) | |
2299 (t | |
2300 (or (and calc-simplify-mode | |
2301 (calc-extensions) | |
2302 (math-normalize-nonstandard)) | |
2303 (let ((args (mapcar 'math-normalize (cdr a)))) | |
2304 (or (condition-case err | |
2305 (let ((func (assq (car a) '( ( + . math-add ) | |
2306 ( - . math-sub ) | |
2307 ( * . math-mul ) | |
2308 ( / . math-div ) | |
2309 ( % . math-mod ) | |
2310 ( ^ . math-pow ) | |
2311 ( neg . math-neg ) | |
2312 ( | . math-concat ) )))) | |
2313 (or (and var-EvalRules | |
2314 (progn | |
2315 (or (eq var-EvalRules math-eval-rules-cache-tag) | |
2316 (progn | |
2317 (calc-extensions) | |
2318 (math-recompile-eval-rules))) | |
2319 (and (or math-eval-rules-cache-other | |
2320 (assq (car a) math-eval-rules-cache)) | |
2321 (math-apply-rewrites | |
2322 (cons (car a) args) | |
2323 (cdr math-eval-rules-cache) | |
2324 nil math-eval-rules-cache)))) | |
2325 (if func | |
2326 (apply (cdr func) args) | |
2327 (and (or (consp (car a)) | |
2328 (fboundp (car a)) | |
2329 (and (not calc-extensions-loaded) | |
2330 (calc-extensions) | |
2331 (fboundp (car a)))) | |
2332 (apply (car a) args))))) | |
2333 (wrong-number-of-arguments | |
2334 (calc-record-why "*Wrong number of arguments" | |
2335 (cons (car a) args)) | |
2336 nil) | |
2337 (wrong-type-argument | |
2338 (or calc-next-why (calc-record-why "Wrong type of argument" | |
2339 (cons (car a) args))) | |
2340 nil) | |
2341 (args-out-of-range | |
2342 (calc-record-why "*Argument out of range" (cons (car a) args)) | |
2343 nil) | |
2344 (inexact-result | |
2345 (calc-record-why "No exact representation for result" | |
2346 (cons (car a) args)) | |
2347 nil) | |
2348 (math-overflow | |
2349 (calc-record-why "*Floating-point overflow occurred" | |
2350 (cons (car a) args)) | |
2351 nil) | |
2352 (math-underflow | |
2353 (calc-record-why "*Floating-point underflow occurred" | |
2354 (cons (car a) args)) | |
2355 nil) | |
2356 (void-variable | |
2357 (if (eq (nth 1 err) 'var-EvalRules) | |
2358 (progn | |
2359 (setq var-EvalRules nil) | |
2360 (math-normalize (cons (car a) args))) | |
2361 (calc-record-why "*Variable is void" (nth 1 err))))) | |
2362 (if (consp (car a)) | |
2363 (math-dimension-error) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2364 (cons (car a) args)))))))) |
40785 | 2365 |
2366 | |
2367 | |
2368 ;;; True if A is a floating-point real or complex number. [P x] [Public] | |
2369 (defun math-floatp (a) | |
2370 (cond ((eq (car-safe a) 'float) t) | |
2371 ((memq (car-safe a) '(cplx polar mod sdev intv)) | |
2372 (or (math-floatp (nth 1 a)) | |
2373 (math-floatp (nth 2 a)) | |
2374 (and (eq (car a) 'intv) (math-floatp (nth 3 a))))) | |
2375 ((eq (car-safe a) 'date) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2376 (math-floatp (nth 1 a))))) |
40785 | 2377 |
2378 | |
2379 | |
2380 ;;; Verify that A is a complete object and return A. [x x] [Public] | |
2381 (defun math-check-complete (a) | |
2382 (cond ((integerp a) a) | |
2383 ((eq (car-safe a) 'incomplete) | |
2384 (calc-incomplete-error a)) | |
2385 ((consp a) a) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2386 (t (error "Invalid data object encountered")))) |
40785 | 2387 |
2388 | |
2389 | |
2390 ;;; Coerce integer A to be a bignum. [B S] | |
2391 (defun math-bignum (a) | |
2392 (if (>= a 0) | |
2393 (cons 'bigpos (math-bignum-big a)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2394 (cons 'bigneg (math-bignum-big (- a))))) |
40785 | 2395 |
2396 (defun math-bignum-big (a) ; [L s] | |
2397 (if (= a 0) | |
2398 nil | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2399 (cons (% a 1000) (math-bignum-big (/ a 1000))))) |
40785 | 2400 |
2401 | |
2402 ;;; Build a normalized floating-point number. [F I S] | |
2403 (defun math-make-float (mant exp) | |
2404 (if (eq mant 0) | |
2405 '(float 0 0) | |
2406 (let* ((ldiff (- calc-internal-prec (math-numdigs mant)))) | |
2407 (if (< ldiff 0) | |
2408 (setq mant (math-scale-rounding mant ldiff) | |
2409 exp (- exp ldiff)))) | |
2410 (if (consp mant) | |
2411 (let ((digs (cdr mant))) | |
2412 (if (= (% (car digs) 10) 0) | |
2413 (progn | |
2414 (while (= (car digs) 0) | |
2415 (setq digs (cdr digs) | |
2416 exp (+ exp 3))) | |
2417 (while (= (% (car digs) 10) 0) | |
2418 (setq digs (math-div10-bignum digs) | |
2419 exp (1+ exp))) | |
2420 (setq mant (math-normalize (cons (car mant) digs)))))) | |
2421 (while (= (% mant 10) 0) | |
2422 (setq mant (/ mant 10) | |
2423 exp (1+ exp)))) | |
2424 (if (and (<= exp -4000000) | |
2425 (<= (+ exp (math-numdigs mant) -1) -4000000)) | |
2426 (signal 'math-underflow nil) | |
2427 (if (and (>= exp 3000000) | |
2428 (>= (+ exp (math-numdigs mant) -1) 4000000)) | |
2429 (signal 'math-overflow nil) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2430 (list 'float mant exp))))) |
40785 | 2431 |
2432 (defun math-div10-bignum (a) ; [l l] | |
2433 (if (cdr a) | |
2434 (cons (+ (/ (car a) 10) (* (% (nth 1 a) 10) 100)) | |
2435 (math-div10-bignum (cdr a))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2436 (list (/ (car a) 10)))) |
40785 | 2437 |
2438 ;;; Coerce A to be a float. [F N; V V] [Public] | |
2439 (defun math-float (a) | |
2440 (cond ((Math-integerp a) (math-make-float a 0)) | |
2441 ((eq (car a) 'frac) (math-div (math-float (nth 1 a)) (nth 2 a))) | |
2442 ((eq (car a) 'float) a) | |
2443 ((memq (car a) '(cplx polar vec hms date sdev mod)) | |
2444 (cons (car a) (mapcar 'math-float (cdr a)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2445 (t (math-float-fancy a)))) |
40785 | 2446 |
2447 | |
2448 (defun math-neg (a) | |
2449 (cond ((not (consp a)) (- a)) | |
2450 ((eq (car a) 'bigpos) (cons 'bigneg (cdr a))) | |
2451 ((eq (car a) 'bigneg) (cons 'bigpos (cdr a))) | |
2452 ((memq (car a) '(frac float)) | |
2453 (list (car a) (Math-integer-neg (nth 1 a)) (nth 2 a))) | |
2454 ((memq (car a) '(cplx vec hms date calcFunc-idn)) | |
2455 (cons (car a) (mapcar 'math-neg (cdr a)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2456 (t (math-neg-fancy a)))) |
40785 | 2457 |
2458 | |
2459 ;;; Compute the number of decimal digits in integer A. [S I] | |
2460 (defun math-numdigs (a) | |
2461 (if (consp a) | |
2462 (if (cdr a) | |
2463 (let* ((len (1- (length a))) | |
2464 (top (nth len a))) | |
2465 (+ (* len 3) (cond ((>= top 100) 0) ((>= top 10) -1) (t -2)))) | |
2466 0) | |
2467 (cond ((>= a 100) (+ (math-numdigs (/ a 1000)) 3)) | |
2468 ((>= a 10) 2) | |
2469 ((>= a 1) 1) | |
2470 ((= a 0) 0) | |
2471 ((> a -10) 1) | |
2472 ((> a -100) 2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2473 (t (math-numdigs (- a)))))) |
40785 | 2474 |
2475 ;;; Multiply (with truncation toward 0) the integer A by 10^N. [I i S] | |
2476 (defun math-scale-int (a n) | |
2477 (cond ((= n 0) a) | |
2478 ((> n 0) (math-scale-left a n)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2479 (t (math-normalize (math-scale-right a (- n)))))) |
40785 | 2480 |
2481 (defun math-scale-left (a n) ; [I I S] | |
2482 (if (= n 0) | |
2483 a | |
2484 (if (consp a) | |
2485 (cons (car a) (math-scale-left-bignum (cdr a) n)) | |
2486 (if (>= n 3) | |
2487 (if (or (>= a 1000) (<= a -1000)) | |
2488 (math-scale-left (math-bignum a) n) | |
2489 (math-scale-left (* a 1000) (- n 3))) | |
2490 (if (= n 2) | |
2491 (if (or (>= a 10000) (<= a -10000)) | |
2492 (math-scale-left (math-bignum a) 2) | |
2493 (* a 100)) | |
2494 (if (or (>= a 100000) (<= a -100000)) | |
2495 (math-scale-left (math-bignum a) 1) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2496 (* a 10))))))) |
40785 | 2497 |
2498 (defun math-scale-left-bignum (a n) | |
2499 (if (>= n 3) | |
2500 (while (>= (setq a (cons 0 a) | |
2501 n (- n 3)) 3))) | |
2502 (if (> n 0) | |
2503 (math-mul-bignum-digit a (if (= n 2) 100 10) 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2504 a)) |
40785 | 2505 |
2506 (defun math-scale-right (a n) ; [i i S] | |
2507 (if (= n 0) | |
2508 a | |
2509 (if (consp a) | |
2510 (cons (car a) (math-scale-right-bignum (cdr a) n)) | |
2511 (if (<= a 0) | |
2512 (if (= a 0) | |
2513 0 | |
2514 (- (math-scale-right (- a) n))) | |
2515 (if (>= n 3) | |
2516 (while (and (> (setq a (/ a 1000)) 0) | |
2517 (>= (setq n (- n 3)) 3)))) | |
2518 (if (= n 2) | |
2519 (/ a 100) | |
2520 (if (= n 1) | |
2521 (/ a 10) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2522 a)))))) |
40785 | 2523 |
2524 (defun math-scale-right-bignum (a n) ; [L L S; l l S] | |
2525 (if (>= n 3) | |
2526 (setq a (nthcdr (/ n 3) a) | |
2527 n (% n 3))) | |
2528 (if (> n 0) | |
2529 (cdr (math-mul-bignum-digit a (if (= n 2) 10 100) 0)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2530 a)) |
40785 | 2531 |
2532 ;;; Multiply (with rounding) the integer A by 10^N. [I i S] | |
2533 (defun math-scale-rounding (a n) | |
2534 (cond ((>= n 0) | |
2535 (math-scale-left a n)) | |
2536 ((consp a) | |
2537 (math-normalize | |
2538 (cons (car a) | |
2539 (let ((val (if (< n -3) | |
2540 (math-scale-right-bignum (cdr a) (- -3 n)) | |
2541 (if (= n -2) | |
2542 (math-mul-bignum-digit (cdr a) 10 0) | |
2543 (if (= n -1) | |
2544 (math-mul-bignum-digit (cdr a) 100 0) | |
2545 (cdr a)))))) ; n = -3 | |
2546 (if (and val (>= (car val) 500)) | |
2547 (if (cdr val) | |
2548 (if (eq (car (cdr val)) 999) | |
2549 (math-add-bignum (cdr val) '(1)) | |
2550 (cons (1+ (car (cdr val))) (cdr (cdr val)))) | |
2551 '(1)) | |
2552 (cdr val)))))) | |
2553 (t | |
2554 (if (< a 0) | |
2555 (- (math-scale-rounding (- a) n)) | |
2556 (if (= n -1) | |
2557 (/ (+ a 5) 10) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2558 (/ (+ (math-scale-right a (- -1 n)) 5) 10)))))) |
40785 | 2559 |
2560 | |
2561 ;;; Compute the sum of A and B. [O O O] [Public] | |
2562 (defun math-add (a b) | |
2563 (or | |
2564 (and (not (or (consp a) (consp b))) | |
2565 (progn | |
2566 (setq a (+ a b)) | |
2567 (if (or (<= a -1000000) (>= a 1000000)) | |
2568 (math-bignum a) | |
2569 a))) | |
2570 (and (Math-zerop a) (not (eq (car-safe a) 'mod)) | |
2571 (if (and (math-floatp a) (Math-ratp b)) (math-float b) b)) | |
2572 (and (Math-zerop b) (not (eq (car-safe b) 'mod)) | |
2573 (if (and (math-floatp b) (Math-ratp a)) (math-float a) a)) | |
2574 (and (Math-objvecp a) (Math-objvecp b) | |
2575 (or | |
2576 (and (Math-integerp a) (Math-integerp b) | |
2577 (progn | |
2578 (or (consp a) (setq a (math-bignum a))) | |
2579 (or (consp b) (setq b (math-bignum b))) | |
2580 (if (eq (car a) 'bigneg) | |
2581 (if (eq (car b) 'bigneg) | |
2582 (cons 'bigneg (math-add-bignum (cdr a) (cdr b))) | |
2583 (math-normalize | |
2584 (let ((diff (math-sub-bignum (cdr b) (cdr a)))) | |
2585 (if (eq diff 'neg) | |
2586 (cons 'bigneg (math-sub-bignum (cdr a) (cdr b))) | |
2587 (cons 'bigpos diff))))) | |
2588 (if (eq (car b) 'bigneg) | |
2589 (math-normalize | |
2590 (let ((diff (math-sub-bignum (cdr a) (cdr b)))) | |
2591 (if (eq diff 'neg) | |
2592 (cons 'bigneg (math-sub-bignum (cdr b) (cdr a))) | |
2593 (cons 'bigpos diff)))) | |
2594 (cons 'bigpos (math-add-bignum (cdr a) (cdr b))))))) | |
2595 (and (Math-ratp a) (Math-ratp b) | |
2596 (calc-extensions) | |
2597 (calc-add-fractions a b)) | |
2598 (and (Math-realp a) (Math-realp b) | |
2599 (progn | |
2600 (or (and (consp a) (eq (car a) 'float)) | |
2601 (setq a (math-float a))) | |
2602 (or (and (consp b) (eq (car b) 'float)) | |
2603 (setq b (math-float b))) | |
2604 (math-add-float a b))) | |
2605 (and (calc-extensions) | |
2606 (math-add-objects-fancy a b)))) | |
2607 (and (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2608 (math-add-symb-fancy a b)))) |
40785 | 2609 |
2610 (defun math-add-bignum (a b) ; [L L L; l l l] | |
2611 (if a | |
2612 (if b | |
2613 (let* ((a (copy-sequence a)) (aa a) (carry nil) sum) | |
2614 (while (and aa b) | |
2615 (if carry | |
2616 (if (< (setq sum (+ (car aa) (car b))) 999) | |
2617 (progn | |
2618 (setcar aa (1+ sum)) | |
2619 (setq carry nil)) | |
2620 (setcar aa (+ sum -999))) | |
2621 (if (< (setq sum (+ (car aa) (car b))) 1000) | |
2622 (setcar aa sum) | |
2623 (setcar aa (+ sum -1000)) | |
2624 (setq carry t))) | |
2625 (setq aa (cdr aa) | |
2626 b (cdr b))) | |
2627 (if carry | |
2628 (if b | |
2629 (nconc a (math-add-bignum b '(1))) | |
2630 (while (eq (car aa) 999) | |
2631 (setcar aa 0) | |
2632 (setq aa (cdr aa))) | |
2633 (if aa | |
2634 (progn | |
2635 (setcar aa (1+ (car aa))) | |
2636 a) | |
2637 (nconc a '(1)))) | |
2638 (if b | |
2639 (nconc a b) | |
2640 a))) | |
2641 a) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2642 b)) |
40785 | 2643 |
2644 (defun math-sub-bignum (a b) ; [l l l] | |
2645 (if b | |
2646 (if a | |
2647 (let* ((a (copy-sequence a)) (aa a) (borrow nil) sum) | |
2648 (while (and aa b) | |
2649 (if borrow | |
2650 (if (>= (setq diff (- (car aa) (car b))) 1) | |
2651 (progn | |
2652 (setcar aa (1- diff)) | |
2653 (setq borrow nil)) | |
2654 (setcar aa (+ diff 999))) | |
2655 (if (>= (setq diff (- (car aa) (car b))) 0) | |
2656 (setcar aa diff) | |
2657 (setcar aa (+ diff 1000)) | |
2658 (setq borrow t))) | |
2659 (setq aa (cdr aa) | |
2660 b (cdr b))) | |
2661 (if borrow | |
2662 (progn | |
2663 (while (eq (car aa) 0) | |
2664 (setcar aa 999) | |
2665 (setq aa (cdr aa))) | |
2666 (if aa | |
2667 (progn | |
2668 (setcar aa (1- (car aa))) | |
2669 a) | |
2670 'neg)) | |
2671 (while (eq (car b) 0) | |
2672 (setq b (cdr b))) | |
2673 (if b | |
2674 'neg | |
2675 a))) | |
2676 (while (eq (car b) 0) | |
2677 (setq b (cdr b))) | |
2678 (and b | |
2679 'neg)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2680 a)) |
40785 | 2681 |
2682 (defun math-add-float (a b) ; [F F F] | |
2683 (let ((ediff (- (nth 2 a) (nth 2 b)))) | |
2684 (if (>= ediff 0) | |
2685 (if (>= ediff (+ calc-internal-prec calc-internal-prec)) | |
2686 a | |
2687 (math-make-float (math-add (nth 1 b) | |
2688 (if (eq ediff 0) | |
2689 (nth 1 a) | |
2690 (math-scale-left (nth 1 a) ediff))) | |
2691 (nth 2 b))) | |
2692 (if (>= (setq ediff (- ediff)) | |
2693 (+ calc-internal-prec calc-internal-prec)) | |
2694 b | |
2695 (math-make-float (math-add (nth 1 a) | |
2696 (math-scale-left (nth 1 b) ediff)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2697 (nth 2 a)))))) |
40785 | 2698 |
2699 ;;; Compute the difference of A and B. [O O O] [Public] | |
2700 (defun math-sub (a b) | |
2701 (if (or (consp a) (consp b)) | |
2702 (math-add a (math-neg b)) | |
2703 (setq a (- a b)) | |
2704 (if (or (<= a -1000000) (>= a 1000000)) | |
2705 (math-bignum a) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2706 a))) |
40785 | 2707 |
2708 (defun math-sub-float (a b) ; [F F F] | |
2709 (let ((ediff (- (nth 2 a) (nth 2 b)))) | |
2710 (if (>= ediff 0) | |
2711 (if (>= ediff (+ calc-internal-prec calc-internal-prec)) | |
2712 a | |
2713 (math-make-float (math-add (Math-integer-neg (nth 1 b)) | |
2714 (if (eq ediff 0) | |
2715 (nth 1 a) | |
2716 (math-scale-left (nth 1 a) ediff))) | |
2717 (nth 2 b))) | |
2718 (if (>= (setq ediff (- ediff)) | |
2719 (+ calc-internal-prec calc-internal-prec)) | |
2720 b | |
2721 (math-make-float (math-add (nth 1 a) | |
2722 (Math-integer-neg | |
2723 (math-scale-left (nth 1 b) ediff))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2724 (nth 2 a)))))) |
40785 | 2725 |
2726 | |
2727 ;;; Compute the product of A and B. [O O O] [Public] | |
2728 (defun math-mul (a b) | |
2729 (or | |
2730 (and (not (consp a)) (not (consp b)) | |
2731 (< a 1000) (> a -1000) (< b 1000) (> b -1000) | |
2732 (* a b)) | |
2733 (and (Math-zerop a) (not (eq (car-safe b) 'mod)) | |
2734 (if (Math-scalarp b) | |
2735 (if (and (math-floatp b) (Math-ratp a)) (math-float a) a) | |
2736 (calc-extensions) | |
2737 (math-mul-zero a b))) | |
2738 (and (Math-zerop b) (not (eq (car-safe a) 'mod)) | |
2739 (if (Math-scalarp a) | |
2740 (if (and (math-floatp a) (Math-ratp b)) (math-float b) b) | |
2741 (calc-extensions) | |
2742 (math-mul-zero b a))) | |
2743 (and (Math-objvecp a) (Math-objvecp b) | |
2744 (or | |
2745 (and (Math-integerp a) (Math-integerp b) | |
2746 (progn | |
2747 (or (consp a) (setq a (math-bignum a))) | |
2748 (or (consp b) (setq b (math-bignum b))) | |
2749 (math-normalize | |
2750 (cons (if (eq (car a) (car b)) 'bigpos 'bigneg) | |
2751 (if (cdr (cdr a)) | |
2752 (if (cdr (cdr b)) | |
2753 (math-mul-bignum (cdr a) (cdr b)) | |
2754 (math-mul-bignum-digit (cdr a) (nth 1 b) 0)) | |
2755 (math-mul-bignum-digit (cdr b) (nth 1 a) 0)))))) | |
2756 (and (Math-ratp a) (Math-ratp b) | |
2757 (calc-extensions) | |
2758 (calc-mul-fractions a b)) | |
2759 (and (Math-realp a) (Math-realp b) | |
2760 (progn | |
2761 (or (and (consp a) (eq (car a) 'float)) | |
2762 (setq a (math-float a))) | |
2763 (or (and (consp b) (eq (car b) 'float)) | |
2764 (setq b (math-float b))) | |
2765 (math-make-float (math-mul (nth 1 a) (nth 1 b)) | |
2766 (+ (nth 2 a) (nth 2 b))))) | |
2767 (and (calc-extensions) | |
2768 (math-mul-objects-fancy a b)))) | |
2769 (and (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2770 (math-mul-symb-fancy a b)))) |
40785 | 2771 |
2772 (defun math-infinitep (a &optional undir) | |
2773 (while (and (consp a) (memq (car a) '(* / neg))) | |
2774 (if (or (not (eq (car a) '*)) (math-infinitep (nth 1 a))) | |
2775 (setq a (nth 1 a)) | |
2776 (setq a (nth 2 a)))) | |
2777 (and (consp a) | |
2778 (eq (car a) 'var) | |
2779 (memq (nth 2 a) '(var-inf var-uinf var-nan)) | |
2780 (if (and undir (eq (nth 2 a) 'var-inf)) | |
2781 '(var uinf var-uinf) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2782 a))) |
40785 | 2783 |
2784 ;;; Multiply digit lists A and B. [L L L; l l l] | |
2785 (defun math-mul-bignum (a b) | |
2786 (and a b | |
2787 (let* ((sum (if (<= (car b) 1) | |
2788 (if (= (car b) 0) | |
2789 (list 0) | |
2790 (copy-sequence a)) | |
2791 (math-mul-bignum-digit a (car b) 0))) | |
2792 (sump sum) c d aa ss prod) | |
2793 (while (setq b (cdr b)) | |
2794 (setq ss (setq sump (or (cdr sump) (setcdr sump (list 0)))) | |
2795 d (car b) | |
2796 c 0 | |
2797 aa a) | |
2798 (while (progn | |
2799 (setcar ss (% (setq prod (+ (+ (car ss) (* (car aa) d)) | |
2800 c)) 1000)) | |
2801 (setq aa (cdr aa))) | |
2802 (setq c (/ prod 1000) | |
2803 ss (or (cdr ss) (setcdr ss (list 0))))) | |
2804 (if (>= prod 1000) | |
2805 (if (cdr ss) | |
2806 (setcar (cdr ss) (+ (/ prod 1000) (car (cdr ss)))) | |
2807 (setcdr ss (list (/ prod 1000)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2808 sum))) |
40785 | 2809 |
2810 ;;; Multiply digit list A by digit D. [L L D D; l l D D] | |
2811 (defun math-mul-bignum-digit (a d c) | |
2812 (if a | |
2813 (if (<= d 1) | |
2814 (and (= d 1) a) | |
2815 (let* ((a (copy-sequence a)) (aa a) prod) | |
2816 (while (progn | |
2817 (setcar aa (% (setq prod (+ (* (car aa) d) c)) 1000)) | |
2818 (cdr aa)) | |
2819 (setq aa (cdr aa) | |
2820 c (/ prod 1000))) | |
2821 (if (>= prod 1000) | |
2822 (setcdr aa (list (/ prod 1000)))) | |
2823 a)) | |
2824 (and (> c 0) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2825 (list c)))) |
40785 | 2826 |
2827 | |
2828 ;;; Compute the integer (quotient . remainder) of A and B, which may be | |
2829 ;;; small or big integers. Type and consistency of truncation is undefined | |
2830 ;;; if A or B is negative. B must be nonzero. [I.I I I] [Public] | |
2831 (defun math-idivmod (a b) | |
2832 (if (eq b 0) | |
2833 (math-reject-arg a "*Division by zero")) | |
2834 (if (or (consp a) (consp b)) | |
2835 (if (and (natnump b) (< b 1000)) | |
2836 (let ((res (math-div-bignum-digit (cdr a) b))) | |
2837 (cons | |
2838 (math-normalize (cons (car a) (car res))) | |
2839 (cdr res))) | |
2840 (or (consp a) (setq a (math-bignum a))) | |
2841 (or (consp b) (setq b (math-bignum b))) | |
2842 (let ((res (math-div-bignum (cdr a) (cdr b)))) | |
2843 (cons | |
2844 (math-normalize (cons (if (eq (car a) (car b)) 'bigpos 'bigneg) | |
2845 (car res))) | |
2846 (math-normalize (cons (car a) (cdr res)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2847 (cons (/ a b) (% a b)))) |
40785 | 2848 |
2849 (defun math-quotient (a b) ; [I I I] [Public] | |
2850 (if (and (not (consp a)) (not (consp b))) | |
2851 (if (= b 0) | |
2852 (math-reject-arg a "*Division by zero") | |
2853 (/ a b)) | |
2854 (if (and (natnump b) (< b 1000)) | |
2855 (if (= b 0) | |
2856 (math-reject-arg a "*Division by zero") | |
2857 (math-normalize (cons (car a) | |
2858 (car (math-div-bignum-digit (cdr a) b))))) | |
2859 (or (consp a) (setq a (math-bignum a))) | |
2860 (or (consp b) (setq b (math-bignum b))) | |
2861 (let* ((alen (1- (length a))) | |
2862 (blen (1- (length b))) | |
2863 (d (/ 1000 (1+ (nth (1- blen) (cdr b))))) | |
2864 (res (math-div-bignum-big (math-mul-bignum-digit (cdr a) d 0) | |
2865 (math-mul-bignum-digit (cdr b) d 0) | |
2866 alen blen))) | |
2867 (math-normalize (cons (if (eq (car a) (car b)) 'bigpos 'bigneg) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2868 (car res))))))) |
40785 | 2869 |
2870 | |
2871 ;;; Divide a bignum digit list by another. [l.l l L] | |
2872 ;;; The following division algorithm is borrowed from Knuth vol. II, sec. 4.3.1 | |
2873 (defun math-div-bignum (a b) | |
2874 (if (cdr b) | |
2875 (let* ((alen (length a)) | |
2876 (blen (length b)) | |
2877 (d (/ 1000 (1+ (nth (1- blen) b)))) | |
2878 (res (math-div-bignum-big (math-mul-bignum-digit a d 0) | |
2879 (math-mul-bignum-digit b d 0) | |
2880 alen blen))) | |
2881 (if (= d 1) | |
2882 res | |
2883 (cons (car res) | |
2884 (car (math-div-bignum-digit (cdr res) d))))) | |
2885 (let ((res (math-div-bignum-digit a (car b)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2886 (cons (car res) (list (cdr res)))))) |
40785 | 2887 |
2888 ;;; Divide a bignum digit list by a digit. [l.D l D] | |
2889 (defun math-div-bignum-digit (a b) | |
2890 (if a | |
2891 (let* ((res (math-div-bignum-digit (cdr a) b)) | |
2892 (num (+ (* (cdr res) 1000) (car a)))) | |
2893 (cons | |
2894 (cons (/ num b) (car res)) | |
2895 (% num b))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2896 '(nil . 0))) |
40785 | 2897 |
2898 (defun math-div-bignum-big (a b alen blen) ; [l.l l L] | |
2899 (if (< alen blen) | |
2900 (cons nil a) | |
2901 (let* ((res (math-div-bignum-big (cdr a) b (1- alen) blen)) | |
2902 (num (cons (car a) (cdr res))) | |
2903 (res2 (math-div-bignum-part num b blen))) | |
2904 (cons | |
2905 (cons (car res2) (car res)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2906 (cdr res2))))) |
40785 | 2907 |
2908 (defun math-div-bignum-part (a b blen) ; a < b*1000 [D.l l L] | |
2909 (let* ((num (+ (* (or (nth blen a) 0) 1000) (or (nth (1- blen) a) 0))) | |
2910 (den (nth (1- blen) b)) | |
2911 (guess (min (/ num den) 999))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2912 (math-div-bignum-try a b (math-mul-bignum-digit b guess 0) guess))) |
40785 | 2913 |
2914 (defun math-div-bignum-try (a b c guess) ; [D.l l l D] | |
2915 (let ((rem (math-sub-bignum a c))) | |
2916 (if (eq rem 'neg) | |
2917 (math-div-bignum-try a b (math-sub-bignum c b) (1- guess)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2918 (cons guess rem)))) |
40785 | 2919 |
2920 | |
2921 ;;; Compute the quotient of A and B. [O O N] [Public] | |
2922 (defun math-div (a b) | |
2923 (or | |
2924 (and (Math-zerop b) | |
2925 (calc-extensions) | |
2926 (math-div-by-zero a b)) | |
2927 (and (Math-zerop a) (not (eq (car-safe b) 'mod)) | |
2928 (if (Math-scalarp b) | |
2929 (if (and (math-floatp b) (Math-ratp a)) (math-float a) a) | |
2930 (calc-extensions) | |
2931 (math-div-zero a b))) | |
2932 (and (Math-objvecp a) (Math-objvecp b) | |
2933 (or | |
2934 (and (Math-integerp a) (Math-integerp b) | |
2935 (let ((q (math-idivmod a b))) | |
2936 (if (eq (cdr q) 0) | |
2937 (car q) | |
2938 (if calc-prefer-frac | |
2939 (progn | |
2940 (calc-extensions) | |
2941 (math-make-frac a b)) | |
2942 (math-div-float (math-make-float a 0) | |
2943 (math-make-float b 0)))))) | |
2944 (and (Math-ratp a) (Math-ratp b) | |
2945 (calc-extensions) | |
2946 (calc-div-fractions a b)) | |
2947 (and (Math-realp a) (Math-realp b) | |
2948 (progn | |
2949 (or (and (consp a) (eq (car a) 'float)) | |
2950 (setq a (math-float a))) | |
2951 (or (and (consp b) (eq (car b) 'float)) | |
2952 (setq b (math-float b))) | |
2953 (math-div-float a b))) | |
2954 (and (calc-extensions) | |
2955 (math-div-objects-fancy a b)))) | |
2956 (and (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2957 (math-div-symb-fancy a b)))) |
40785 | 2958 |
2959 (defun math-div-float (a b) ; [F F F] | |
2960 (let ((ldiff (max (- (1+ calc-internal-prec) | |
2961 (- (math-numdigs (nth 1 a)) (math-numdigs (nth 1 b)))) | |
2962 0))) | |
2963 (math-make-float (math-quotient (math-scale-int (nth 1 a) ldiff) (nth 1 b)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
2964 (- (- (nth 2 a) (nth 2 b)) ldiff)))) |
40785 | 2965 |
2966 | |
2967 | |
2968 | |
2969 | |
2970 ;;; Format the number A as a string. [X N; X Z] [Public] | |
2971 (defun math-format-stack-value (entry) | |
2972 (setq calc-selection-cache-entry calc-selection-cache-default-entry) | |
2973 (let* ((a (car entry)) | |
2974 (math-comp-selected (nth 2 entry)) | |
2975 (c (cond ((null a) "<nil>") | |
2976 ((eq calc-display-raw t) (format "%s" a)) | |
2977 ((stringp a) a) | |
45769 | 2978 ((eq a 'top-of-stack) (propertize "." 'font-lock-face 'bold)) |
40785 | 2979 (calc-prepared-composition |
2980 calc-prepared-composition) | |
2981 ((and (Math-scalarp a) | |
2982 (memq calc-language '(nil flat unform)) | |
2983 (null math-comp-selected)) | |
2984 (math-format-number a)) | |
2985 (t (calc-extensions) | |
2986 (math-compose-expr a 0)))) | |
2987 (off (math-stack-value-offset c)) | |
2988 s w) | |
2989 (and math-comp-selected (setq calc-any-selections t)) | |
2990 (setq w (cdr off) | |
2991 off (car off)) | |
45769 | 2992 (when (> off 0) |
2993 (setq c (math-comp-concat (make-string off ? ) c))) | |
40785 | 2994 (or (equal calc-left-label "") |
2995 (setq c (math-comp-concat (if (eq a 'top-of-stack) | |
2996 (make-string (length calc-left-label) ? ) | |
2997 calc-left-label) | |
2998 c))) | |
45769 | 2999 (when calc-line-numbering |
3000 (setq c (math-comp-concat (if (eq calc-language 'big) | |
46807
f57a8a1712ae
(math-format-stack-value): Revert a broken
David Kastrup <dak@gnu.org>
parents:
45769
diff
changeset
|
3001 (if math-comp-selected |
f57a8a1712ae
(math-format-stack-value): Revert a broken
David Kastrup <dak@gnu.org>
parents:
45769
diff
changeset
|
3002 '(tag t "1: ") |
f57a8a1712ae
(math-format-stack-value): Revert a broken
David Kastrup <dak@gnu.org>
parents:
45769
diff
changeset
|
3003 "1: ") |
45769 | 3004 " ") |
3005 c))) | |
3006 (unless (or (equal calc-right-label "") | |
3007 (eq a 'top-of-stack)) | |
3008 (calc-extensions) | |
3009 (setq c (list 'horiz c | |
3010 (make-string (max (- w (math-comp-width c) | |
3011 (length calc-right-label)) 0) ? ) | |
3012 '(break -1) | |
3013 calc-right-label))) | |
40785 | 3014 (setq s (if (stringp c) |
3015 (if calc-display-raw | |
3016 (prin1-to-string c) | |
3017 c) | |
3018 (math-composition-to-string c w))) | |
45769 | 3019 (when calc-language-output-filter |
3020 (setq s (funcall calc-language-output-filter s))) | |
40785 | 3021 (if (eq calc-language 'big) |
3022 (setq s (concat s "\n")) | |
45769 | 3023 (when calc-line-numbering |
3024 (aset s 0 ?1) | |
3025 (aset s 1 ?:))) | |
40785 | 3026 (setcar (cdr entry) (calc-count-lines s)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3027 s)) |
40785 | 3028 |
3029 (defun math-stack-value-offset (c) | |
3030 (let* ((num (if calc-line-numbering 4 0)) | |
3031 (wid (calc-window-width)) | |
3032 off) | |
3033 (if calc-display-just | |
3034 (progn | |
3035 (calc-extensions) | |
3036 (math-stack-value-offset-fancy)) | |
3037 (setq off (or calc-display-origin 0)) | |
45769 | 3038 (when (integerp calc-line-breaking) |
3039 (setq wid calc-line-breaking))) | |
40785 | 3040 (cons (max (- off (length calc-left-label)) 0) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3041 (+ wid num)))) |
40785 | 3042 |
3043 (defun calc-count-lines (s) | |
3044 (let ((pos 0) | |
3045 (num 1)) | |
3046 (while (setq newpos (string-match "\n" s pos)) | |
3047 (setq pos (1+ newpos) | |
3048 num (1+ num))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3049 num)) |
40785 | 3050 |
3051 (defun math-format-value (a &optional w) | |
3052 (if (and (Math-scalarp a) | |
3053 (memq calc-language '(nil flat unform))) | |
3054 (math-format-number a) | |
3055 (calc-extensions) | |
3056 (let ((calc-line-breaking nil)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3057 (math-composition-to-string (math-compose-expr a 0) w)))) |
40785 | 3058 |
3059 (defun calc-window-width () | |
3060 (if calc-embedded-info | |
3061 (let ((win (get-buffer-window (aref calc-embedded-info 0)))) | |
40999
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3062 (1- (if win (window-width win) (frame-width)))) |
40785 | 3063 (- (window-width (get-buffer-window (current-buffer))) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3064 (if calc-line-numbering 5 1)))) |
40785 | 3065 |
3066 (defun math-comp-concat (c1 c2) | |
3067 (if (and (stringp c1) (stringp c2)) | |
3068 (concat c1 c2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3069 (list 'horiz c1 c2))) |
40785 | 3070 |
3071 | |
3072 | |
3073 ;;; Format an expression as a one-line string suitable for re-reading. | |
3074 | |
3075 (defun math-format-flat-expr (a prec) | |
3076 (cond | |
3077 ((or (not (or (consp a) (integerp a))) | |
3078 (eq calc-display-raw t)) | |
3079 (let ((print-escape-newlines t)) | |
3080 (concat "'" (prin1-to-string a)))) | |
3081 ((Math-scalarp a) | |
3082 (let ((calc-group-digits nil) | |
3083 (calc-point-char ".") | |
3084 (calc-frac-format (if (> (length (car calc-frac-format)) 1) | |
3085 '("::" nil) '(":" nil))) | |
3086 (calc-complex-format nil) | |
3087 (calc-hms-format "%s@ %s' %s\"") | |
3088 (calc-language nil)) | |
3089 (math-format-number a))) | |
3090 (t | |
3091 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3092 (math-format-flat-expr-fancy a prec)))) |
40785 | 3093 |
3094 | |
3095 | |
3096 ;;; Format a number as a string. | |
3097 (defun math-format-number (a &optional prec) ; [X N] [Public] | |
3098 (cond | |
3099 ((eq calc-display-raw t) (format "%s" a)) | |
3100 ((and (nth 1 calc-frac-format) (Math-integerp a)) | |
3101 (calc-extensions) | |
3102 (math-format-number (math-adjust-fraction a))) | |
3103 ((integerp a) | |
3104 (if (not (or calc-group-digits calc-leading-zeros)) | |
3105 (if (= calc-number-radix 10) | |
3106 (int-to-string a) | |
3107 (if (< a 0) | |
3108 (concat "-" (math-format-number (- a))) | |
3109 (calc-extensions) | |
3110 (if math-radix-explicit-format | |
3111 (if calc-radix-formatter | |
3112 (funcall calc-radix-formatter | |
3113 calc-number-radix | |
3114 (if (= calc-number-radix 2) | |
3115 (math-format-binary a) | |
3116 (math-format-radix a))) | |
3117 (format "%d#%s" calc-number-radix | |
3118 (if (= calc-number-radix 2) | |
3119 (math-format-binary a) | |
3120 (math-format-radix a)))) | |
3121 (math-format-radix a)))) | |
3122 (math-format-number (math-bignum a)))) | |
3123 ((stringp a) a) | |
3124 ((not (consp a)) (prin1-to-string a)) | |
3125 ((eq (car a) 'bigpos) (math-format-bignum (cdr a))) | |
3126 ((eq (car a) 'bigneg) (concat "-" (math-format-bignum (cdr a)))) | |
3127 ((and (eq (car a) 'float) (= calc-number-radix 10)) | |
3128 (if (Math-integer-negp (nth 1 a)) | |
3129 (concat "-" (math-format-number (math-neg a))) | |
3130 (let ((mant (nth 1 a)) | |
3131 (exp (nth 2 a)) | |
3132 (fmt (car calc-float-format)) | |
3133 (figs (nth 1 calc-float-format)) | |
3134 (point calc-point-char) | |
3135 str) | |
3136 (if (and (eq fmt 'fix) | |
3137 (or (and (< figs 0) (setq figs (- figs))) | |
3138 (> (+ exp (math-numdigs mant)) (- figs)))) | |
3139 (progn | |
3140 (setq mant (math-scale-rounding mant (+ exp figs)) | |
3141 str (if (integerp mant) | |
3142 (int-to-string mant) | |
3143 (math-format-bignum-decimal (cdr mant)))) | |
3144 (if (<= (length str) figs) | |
3145 (setq str (concat (make-string (1+ (- figs (length str))) ?0) | |
3146 str))) | |
3147 (if (> figs 0) | |
3148 (setq str (concat (substring str 0 (- figs)) point | |
3149 (substring str (- figs)))) | |
3150 (setq str (concat str point))) | |
44574
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3151 (when calc-group-digits |
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3152 (require 'calc-ext) |
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3153 (setq str (math-group-float str)))) |
45769 | 3154 (when (< figs 0) |
3155 (setq figs (+ calc-internal-prec figs))) | |
3156 (when (> figs 0) | |
3157 (let ((adj (- figs (math-numdigs mant)))) | |
3158 (when (< adj 0) | |
3159 (setq mant (math-scale-rounding mant adj) | |
3160 exp (- exp adj))))) | |
40785 | 3161 (setq str (if (integerp mant) |
3162 (int-to-string mant) | |
3163 (math-format-bignum-decimal (cdr mant)))) | |
3164 (let* ((len (length str)) | |
3165 (dpos (+ exp len))) | |
3166 (if (and (eq fmt 'float) | |
3167 (<= dpos (+ calc-internal-prec calc-display-sci-high)) | |
3168 (>= dpos (+ calc-display-sci-low 2))) | |
3169 (progn | |
3170 (cond | |
3171 ((= dpos 0) | |
3172 (setq str (concat "0" point str))) | |
3173 ((and (<= exp 0) (> dpos 0)) | |
3174 (setq str (concat (substring str 0 dpos) point | |
3175 (substring str dpos)))) | |
3176 ((> exp 0) | |
3177 (setq str (concat str (make-string exp ?0) point))) | |
3178 (t ; (< dpos 0) | |
3179 (setq str (concat "0" point | |
3180 (make-string (- dpos) ?0) str)))) | |
44574
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3181 (when calc-group-digits |
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3182 (require 'calc-ext) |
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3183 (setq str (math-group-float str)))) |
40785 | 3184 (let* ((eadj (+ exp len)) |
3185 (scale (if (eq fmt 'eng) | |
3186 (1+ (math-mod (+ eadj 300002) 3)) | |
3187 1))) | |
3188 (if (> scale (length str)) | |
3189 (setq str (concat str (make-string (- scale (length str)) | |
3190 ?0)))) | |
3191 (if (< scale (length str)) | |
3192 (setq str (concat (substring str 0 scale) point | |
3193 (substring str scale)))) | |
44574
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3194 (when calc-group-digits |
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3195 (require 'calc-ext) |
f9b633c7d323
(math-format-number): Load `calc-ext' before we call
Colin Walters <walters@gnu.org>
parents:
44249
diff
changeset
|
3196 (setq str (math-group-float str))) |
40785 | 3197 (setq str (format (if (memq calc-language '(math maple)) |
3198 (if (and prec (> prec 191)) | |
3199 "(%s*10.^%d)" "%s*10.^%d") | |
3200 "%se%d") | |
3201 str (- eadj scale))))))) | |
3202 str))) | |
3203 (t | |
3204 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3205 (math-format-number-fancy a prec)))) |
40785 | 3206 |
3207 (defun math-format-bignum (a) ; [X L] | |
3208 (if (and (= calc-number-radix 10) | |
3209 (not calc-leading-zeros) | |
3210 (not calc-group-digits)) | |
3211 (math-format-bignum-decimal a) | |
3212 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3213 (math-format-bignum-fancy a))) |
40785 | 3214 |
3215 (defun math-format-bignum-decimal (a) ; [X L] | |
3216 (if a | |
3217 (let ((s "")) | |
3218 (while (cdr (cdr a)) | |
3219 (setq s (concat (format "%06d" (+ (* (nth 1 a) 1000) (car a))) s) | |
3220 a (cdr (cdr a)))) | |
3221 (concat (int-to-string (+ (* (or (nth 1 a) 0) 1000) (car a))) s)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3222 "0")) |
40785 | 3223 |
3224 | |
3225 | |
3226 ;;; Parse a simple number in string form. [N X] [Public] | |
3227 (defun math-read-number (s) | |
3228 (math-normalize | |
3229 (cond | |
3230 | |
3231 ;; Integers (most common case) | |
3232 ((string-match "\\` *\\([0-9]+\\) *\\'" s) | |
3233 (let ((digs (math-match-substring s 1))) | |
3234 (if (and (eq calc-language 'c) | |
3235 (> (length digs) 1) | |
3236 (eq (aref digs 0) ?0)) | |
3237 (math-read-number (concat "8#" digs)) | |
3238 (if (<= (length digs) 6) | |
3239 (string-to-int digs) | |
3240 (cons 'bigpos (math-read-bignum digs)))))) | |
3241 | |
3242 ;; Clean up the string if necessary | |
3243 ((string-match "\\`\\(.*\\)[ \t\n]+\\([^\001]*\\)\\'" s) | |
3244 (math-read-number (concat (math-match-substring s 1) | |
3245 (math-match-substring s 2)))) | |
3246 | |
3247 ;; Plus and minus signs | |
3248 ((string-match "^[-_+]\\(.*\\)$" s) | |
3249 (let ((val (math-read-number (math-match-substring s 1)))) | |
3250 (and val (if (eq (aref s 0) ?+) val (math-neg val))))) | |
3251 | |
3252 ;; Forms that require extensions module | |
3253 ((string-match "[^-+0-9eE.]" s) | |
3254 (calc-extensions) | |
3255 (math-read-number-fancy s)) | |
3256 | |
3257 ;; Decimal point | |
3258 ((string-match "^\\([0-9]*\\)\\.\\([0-9]*\\)$" s) | |
3259 (let ((int (math-match-substring s 1)) | |
3260 (frac (math-match-substring s 2))) | |
3261 (let ((ilen (length int)) | |
3262 (flen (length frac))) | |
3263 (let ((int (if (> ilen 0) (math-read-number int) 0)) | |
3264 (frac (if (> flen 0) (math-read-number frac) 0))) | |
3265 (and int frac (or (> ilen 0) (> flen 0)) | |
3266 (list 'float | |
3267 (math-add (math-scale-int int flen) frac) | |
3268 (- flen))))))) | |
3269 | |
3270 ;; "e" notation | |
3271 ((string-match "^\\(.*\\)[eE]\\([-+]?[0-9]+\\)$" s) | |
3272 (let ((mant (math-match-substring s 1)) | |
3273 (exp (math-match-substring s 2))) | |
3274 (let ((mant (if (> (length mant) 0) (math-read-number mant) 1)) | |
3275 (exp (if (<= (length exp) (if (memq (aref exp 0) '(?+ ?-)) 8 7)) | |
3276 (string-to-int exp)))) | |
3277 (and mant exp (Math-realp mant) (> exp -4000000) (< exp 4000000) | |
3278 (let ((mant (math-float mant))) | |
3279 (list 'float (nth 1 mant) (+ (nth 2 mant) exp))))))) | |
3280 | |
3281 ;; Syntax error! | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3282 (t nil)))) |
40785 | 3283 |
3284 (defun math-match-substring (s n) | |
3285 (if (match-beginning n) | |
3286 (substring s (match-beginning n) (match-end n)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3287 "")) |
40785 | 3288 |
3289 (defun math-read-bignum (s) ; [l X] | |
3290 (if (> (length s) 3) | |
3291 (cons (string-to-int (substring s -3)) | |
3292 (math-read-bignum (substring s 0 -3))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3293 (list (string-to-int s)))) |
40785 | 3294 |
3295 | |
3296 (defconst math-tex-ignore-words | |
3297 '( ("\\hbox") ("\\mbox") ("\\text") ("\\left") ("\\right") | |
3298 ("\\,") ("\\>") ("\\:") ("\\;") ("\\!") ("\\ ") | |
3299 ("\\quad") ("\\qquad") ("\\hfil") ("\\hfill") | |
3300 ("\\displaystyle") ("\\textstyle") ("\\dsize") ("\\tsize") | |
3301 ("\\scriptstyle") ("\\scriptscriptstyle") ("\\ssize") ("\\sssize") | |
3302 ("\\rm") ("\\bf") ("\\it") ("\\sl") | |
3303 ("\\roman") ("\\bold") ("\\italic") ("\\slanted") | |
3304 ("\\cal") ("\\mit") ("\\Cal") ("\\Bbb") ("\\frak") ("\\goth") | |
3305 ("\\evalto") | |
3306 ("\\matrix" mat) ("\\bmatrix" mat) ("\\pmatrix" mat) | |
3307 ("\\cr" punc ";") ("\\\\" punc ";") ("\\*" punc "*") | |
3308 ("\\{" punc "[") ("\\}" punc "]") | |
3309 )) | |
3310 | |
3311 (defconst math-eqn-ignore-words | |
3312 '( ("roman") ("bold") ("italic") ("mark") ("lineup") ("evalto") | |
3313 ("left" ("floor") ("ceil")) | |
3314 ("right" ("floor") ("ceil")) | |
3315 ("arc" ("sin") ("cos") ("tan") ("sinh") ("cosh") ("tanh")) | |
3316 ("size" n) ("font" n) ("fwd" n) ("back" n) ("up" n) ("down" n) | |
3317 ("above" punc ",") | |
3318 )) | |
3319 | |
3320 (defconst math-standard-opers | |
3321 '( ( "_" calcFunc-subscr 1200 1201 ) | |
3322 ( "%" calcFunc-percent 1100 -1 ) | |
3323 ( "u+" ident -1 1000 ) | |
3324 ( "u-" neg -1 1000 197 ) | |
3325 ( "u!" calcFunc-lnot -1 1000 ) | |
3326 ( "mod" mod 400 400 185 ) | |
3327 ( "+/-" sdev 300 300 185 ) | |
3328 ( "!!" calcFunc-dfact 210 -1 ) | |
3329 ( "!" calcFunc-fact 210 -1 ) | |
3330 ( "^" ^ 201 200 ) | |
3331 ( "**" ^ 201 200 ) | |
3332 ( "*" * 196 195 ) | |
3333 ( "2x" * 196 195 ) | |
3334 ( "/" / 190 191 ) | |
3335 ( "%" % 190 191 ) | |
3336 ( "\\" calcFunc-idiv 190 191 ) | |
3337 ( "+" + 180 181 ) | |
3338 ( "-" - 180 181 ) | |
3339 ( "|" | 170 171 ) | |
3340 ( "<" calcFunc-lt 160 161 ) | |
3341 ( ">" calcFunc-gt 160 161 ) | |
3342 ( "<=" calcFunc-leq 160 161 ) | |
3343 ( ">=" calcFunc-geq 160 161 ) | |
3344 ( "=" calcFunc-eq 160 161 ) | |
3345 ( "==" calcFunc-eq 160 161 ) | |
3346 ( "!=" calcFunc-neq 160 161 ) | |
3347 ( "&&" calcFunc-land 110 111 ) | |
3348 ( "||" calcFunc-lor 100 101 ) | |
3349 ( "?" (math-read-if) 91 90 ) | |
3350 ( "!!!" calcFunc-pnot -1 85 ) | |
3351 ( "&&&" calcFunc-pand 80 81 ) | |
3352 ( "|||" calcFunc-por 75 76 ) | |
3353 ( ":=" calcFunc-assign 51 50 ) | |
3354 ( "::" calcFunc-condition 45 46 ) | |
3355 ( "=>" calcFunc-evalto 40 41 ) | |
41270
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
3356 ( "=>" calcFunc-evalto 40 -1 ))) |
711f18abaf57
(calc-record-compilation-date): Remove.
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
3357 (defvar math-expr-opers math-standard-opers) |
40785 | 3358 |
3359 ;;;###autoload | |
3360 (defun calc-grab-region (top bot arg) | |
3361 "Parse the region as a vector of numbers and push it on the Calculator stack." | |
3362 (interactive "r\nP") | |
3363 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3364 (calc-do-grab-region top bot arg)) |
40785 | 3365 |
3366 ;;;###autoload | |
3367 (defun calc-grab-rectangle (top bot arg) | |
3368 "Parse a rectangle as a matrix of numbers and push it on the Calculator stack." | |
3369 (interactive "r\nP") | |
3370 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3371 (calc-do-grab-rectangle top bot arg)) |
40785 | 3372 |
3373 (defun calc-grab-sum-down (top bot arg) | |
3374 "Parse a rectangle as a matrix of numbers and sum its columns." | |
3375 (interactive "r\nP") | |
3376 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3377 (calc-do-grab-rectangle top bot arg 'calcFunc-reduced)) |
40785 | 3378 |
3379 (defun calc-grab-sum-across (top bot arg) | |
3380 "Parse a rectangle as a matrix of numbers and sum its rows." | |
3381 (interactive "r\nP") | |
3382 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3383 (calc-do-grab-rectangle top bot arg 'calcFunc-reducea)) |
40785 | 3384 |
3385 | |
3386 ;;;###autoload | |
3387 (defun calc-embedded (arg &optional end obeg oend) | |
3388 "Start Calc Embedded mode on the formula surrounding point." | |
3389 (interactive "P") | |
3390 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3391 (calc-do-embedded arg end obeg oend)) |
40785 | 3392 |
3393 ;;;###autoload | |
3394 (defun calc-embedded-activate (&optional arg cbuf) | |
3395 "Scan the current editing buffer for all embedded := and => formulas. | |
3396 Also looks for the equivalent TeX words, \\gets and \\evalto." | |
3397 (interactive "P") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3398 (calc-do-embedded-activate arg cbuf)) |
40785 | 3399 |
3400 (defun calc-user-invocation () | |
3401 (interactive) | |
45769 | 3402 (unless (stringp calc-invocation-macro) |
3403 (error "Use `Z I' inside Calc to define a `M-# Z' keyboard macro")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3404 (execute-kbd-macro calc-invocation-macro nil)) |
40785 | 3405 |
3406 ;;; User-programmability. | |
3407 | |
3408 ;;;###autoload | |
3409 (defmacro defmath (func args &rest body) ; [Public] | |
3410 (calc-extensions) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3411 (math-do-defmath func args body)) |
40785 | 3412 |
3413 ;;; Functions needed for Lucid Emacs support. | |
3414 | |
3415 (defun calc-read-key (&optional optkey) | |
3416 (cond (calc-emacs-type-lucid | |
3417 (let ((event (next-command-event))) | |
3418 (let ((key (event-to-character event t t))) | |
3419 (or key optkey (error "Expected a plain keystroke")) | |
3420 (cons key event)))) | |
3421 (calc-emacs-type-gnu19 | |
3422 (let ((key (read-event))) | |
3423 (cons key key))) | |
3424 (t | |
3425 (let ((key (read-char))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3426 (cons key key))))) |
40785 | 3427 |
3428 (defun calc-unread-command (&optional input) | |
40999
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3429 (if (featurep 'xemacs) |
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3430 (setq unread-command-event |
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3431 (if (integerp input) (character-to-event input) |
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3432 (or input last-command-event))) |
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3433 (push (or input last-command-event) unread-command-events))) |
40785 | 3434 |
3435 (defun calc-clear-unread-commands () | |
40999
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3436 (if (featurep 'xemacs) |
40785 | 3437 (calc-emacs-type-lucid (setq unread-command-event nil)) |
40999
d5ccdce87268
Use `frame-width' instead of `screen-width',
Eli Zaretskii <eliz@gnu.org>
parents:
40911
diff
changeset
|
3438 (setq unread-command-events nil))) |
40785 | 3439 |
45769 | 3440 (when calc-always-load-extensions |
3441 (calc-extensions) | |
3442 (calc-load-everything)) | |
40785 | 3443 |
3444 | |
3445 (run-hooks 'calc-load-hook) | |
3446 | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40999
diff
changeset
|
3447 ;;; calc.el ends here |