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