Mercurial > emacs
comparison lisp/calc/calc-stuff.el @ 41047:73f364fd8aaa
Style cleanup; don't put closing parens on their
own line, add "foo.el ends here" to each file, and update
copyright date.
author | Colin Walters <walters@gnu.org> |
---|---|
date | Wed, 14 Nov 2001 09:09:09 +0000 |
parents | 2fb9d407ae73 |
children | fcd507927105 |
comparison
equal
deleted
inserted
replaced
41046:14b73d89514a | 41047:73f364fd8aaa |
---|---|
1 ;; Calculator for GNU Emacs, part II [calc-stuff.el] | 1 ;; Calculator for GNU Emacs, part II [calc-stuff.el] |
2 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. | 2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
3 ;; Written by Dave Gillespie, daveg@synaptics.com. | 3 ;; Written by Dave Gillespie, daveg@synaptics.com. |
4 | 4 |
5 ;; This file is part of GNU Emacs. | 5 ;; This file is part of GNU Emacs. |
6 | 6 |
7 ;; GNU Emacs is distributed in the hope that it will be useful, | 7 ;; GNU Emacs is distributed in the hope that it will be useful, |
41 (setq num (math-trunc num))) | 41 (setq num (math-trunc num))) |
42 (or (integerp num) | 42 (or (integerp num) |
43 (error "Argument must be a small integer")) | 43 (error "Argument must be a small integer")) |
44 (calc-pop-stack 1) | 44 (calc-pop-stack 1) |
45 (setq prefix-arg num) | 45 (setq prefix-arg num) |
46 (message "%d-" num)))) ; a (lame) simulation of the real thing... | 46 (message "%d-" num))))) ; a (lame) simulation of the real thing... |
47 ) | |
48 | 47 |
49 | 48 |
50 (defun calc-more-recursion-depth (n) | 49 (defun calc-more-recursion-depth (n) |
51 (interactive "P") | 50 (interactive "P") |
52 (calc-wrapper | 51 (calc-wrapper |
54 (calc-less-recursion-depth n) | 53 (calc-less-recursion-depth n) |
55 (let ((n (if n (prefix-numeric-value n) 2))) | 54 (let ((n (if n (prefix-numeric-value n) 2))) |
56 (if (> n 1) | 55 (if (> n 1) |
57 (setq max-specpdl-size (* max-specpdl-size n) | 56 (setq max-specpdl-size (* max-specpdl-size n) |
58 max-lisp-eval-depth (* max-lisp-eval-depth n)))) | 57 max-lisp-eval-depth (* max-lisp-eval-depth n)))) |
59 (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth))) | 58 (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth)))) |
60 ) | |
61 | 59 |
62 (defun calc-less-recursion-depth (n) | 60 (defun calc-less-recursion-depth (n) |
63 (interactive "P") | 61 (interactive "P") |
64 (let ((n (if n (prefix-numeric-value n) 2))) | 62 (let ((n (if n (prefix-numeric-value n) 2))) |
65 (if (> n 1) | 63 (if (> n 1) |
66 (setq max-specpdl-size | 64 (setq max-specpdl-size |
67 (max (/ max-specpdl-size n) 600) | 65 (max (/ max-specpdl-size n) 600) |
68 max-lisp-eval-depth | 66 max-lisp-eval-depth |
69 (max (/ max-lisp-eval-depth n) 200)))) | 67 (max (/ max-lisp-eval-depth n) 200)))) |
70 (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth) | 68 (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth)) |
71 ) | |
72 | 69 |
73 | 70 |
74 (defun calc-explain-why (why &optional more) | 71 (defun calc-explain-why (why &optional more) |
75 (if (eq (car why) '*) | 72 (if (eq (car why) '*) |
76 (setq why (cdr why))) | 73 (setq why (cdr why))) |
135 (and (car why) | 132 (and (car why) |
136 (setq msg (concat msg punc (if (stringp (car why)) | 133 (setq msg (concat msg punc (if (stringp (car why)) |
137 (car why) | 134 (car why) |
138 (math-format-flat-expr (car why) 0))) | 135 (math-format-flat-expr (car why) 0))) |
139 punc ", "))) | 136 punc ", "))) |
140 (message "%s%s" msg (if more " [w=more]" ""))) | 137 (message "%s%s" msg (if more " [w=more]" "")))) |
141 ) | |
142 | 138 |
143 (defun calc-why () | 139 (defun calc-why () |
144 (interactive) | 140 (interactive) |
145 (if (not (eq this-command last-command)) | 141 (if (not (eq this-command last-command)) |
146 (if (eq last-command calc-last-why-command) | 142 (if (eq last-command calc-last-why-command) |
152 (setq calc-which-why (cdr calc-which-why))) | 148 (setq calc-which-why (cdr calc-which-why))) |
153 (if calc-why | 149 (if calc-why |
154 (progn | 150 (progn |
155 (message "(No further explanations available)") | 151 (message "(No further explanations available)") |
156 (setq calc-which-why calc-why)) | 152 (setq calc-which-why calc-why)) |
157 (message "No explanations available"))) | 153 (message "No explanations available")))) |
158 ) | |
159 (setq calc-which-why nil) | 154 (setq calc-which-why nil) |
160 (setq calc-last-why-command nil) | 155 (setq calc-last-why-command nil) |
161 | 156 |
162 | 157 |
163 (defun calc-version () | 158 (defun calc-version () |
182 math-graph-var-cache nil | 177 math-graph-var-cache nil |
183 math-graph-data-cache nil | 178 math-graph-data-cache nil |
184 math-format-date-cache nil | 179 math-format-date-cache nil |
185 math-holidays-cache-tag t) | 180 math-holidays-cache-tag t) |
186 (mapcar (function (lambda (x) (set x -100))) math-cache-list) | 181 (mapcar (function (lambda (x) (set x -100))) math-cache-list) |
187 (message "All internal calculator caches have been reset.")) | 182 (message "All internal calculator caches have been reset."))) |
188 ) | |
189 | 183 |
190 | 184 |
191 ;;; Conversions. | 185 ;;; Conversions. |
192 | 186 |
193 (defun calc-clean (n) | 187 (defun calc-clean (n) |
201 (list func | 195 (list func |
202 (calc-top-n 1) | 196 (calc-top-n 1) |
203 (if (<= n 0) | 197 (if (<= n 0) |
204 (+ n calc-internal-prec) | 198 (+ n calc-internal-prec) |
205 n))) | 199 n))) |
206 (list func (calc-top-n 1))))))) | 200 (list func (calc-top-n 1)))))))) |
207 ) | |
208 | 201 |
209 (defun calc-clean-num (num) | 202 (defun calc-clean-num (num) |
210 (interactive "P") | 203 (interactive "P") |
211 (calc-clean (- (if num | 204 (calc-clean (- (if num |
212 (prefix-numeric-value num) | 205 (prefix-numeric-value num) |
213 (if (and (>= last-command-char ?0) | 206 (if (and (>= last-command-char ?0) |
214 (<= last-command-char ?9)) | 207 (<= last-command-char ?9)) |
215 (- last-command-char ?0) | 208 (- last-command-char ?0) |
216 (error "Number required"))))) | 209 (error "Number required")))))) |
217 ) | |
218 | 210 |
219 | 211 |
220 (defun calcFunc-clean (a &optional prec) ; [X X S] [Public] | 212 (defun calcFunc-clean (a &optional prec) ; [X X S] [Public] |
221 (if prec | 213 (if prec |
222 (cond ((Math-messy-integerp prec) | 214 (cond ((Math-messy-integerp prec) |
255 a) | 247 a) |
256 0) | 248 0) |
257 a)) | 249 a)) |
258 ((Math-objectp a) a) | 250 ((Math-objectp a) a) |
259 ((math-infinitep a) a) | 251 ((math-infinitep a) a) |
260 (t (list 'calcFunc-clean a)))) | 252 (t (list 'calcFunc-clean a))))) |
261 ) | |
262 (setq math-chopping-small nil) | 253 (setq math-chopping-small nil) |
263 | 254 |
264 (defun calcFunc-pclean (a &optional prec) | 255 (defun calcFunc-pclean (a &optional prec) |
265 (math-map-over-constants (function (lambda (x) (calcFunc-clean x prec))) | 256 (math-map-over-constants (function (lambda (x) (calcFunc-clean x prec))) |
266 a) | 257 a)) |
267 ) | |
268 | 258 |
269 (defun calcFunc-pfloat (a) | 259 (defun calcFunc-pfloat (a) |
270 (math-map-over-constants 'math-float a) | 260 (math-map-over-constants 'math-float a)) |
271 ) | |
272 | 261 |
273 (defun calcFunc-pfrac (a &optional tol) | 262 (defun calcFunc-pfrac (a &optional tol) |
274 (math-map-over-constants (function (lambda (x) (calcFunc-frac x tol))) | 263 (math-map-over-constants (function (lambda (x) (calcFunc-frac x tol))) |
275 a) | 264 a)) |
276 ) | |
277 | 265 |
278 (defun math-map-over-constants (func expr) | 266 (defun math-map-over-constants (func expr) |
279 (math-map-over-constants-rec expr) | 267 (math-map-over-constants-rec expr)) |
280 ) | |
281 | 268 |
282 (defun math-map-over-constants-rec (expr) | 269 (defun math-map-over-constants-rec (expr) |
283 (cond ((or (Math-primp expr) | 270 (cond ((or (Math-primp expr) |
284 (memq (car expr) '(intv sdev))) | 271 (memq (car expr) '(intv sdev))) |
285 (or (and (Math-objectp expr) | 272 (or (and (Math-objectp expr) |
290 (= (length expr) 3) | 277 (= (length expr) 3) |
291 (Math-integerp (nth 2 expr))) | 278 (Math-integerp (nth 2 expr))) |
292 (list (car expr) | 279 (list (car expr) |
293 (math-map-over-constants-rec (nth 1 expr)) | 280 (math-map-over-constants-rec (nth 1 expr)) |
294 (nth 2 expr))) | 281 (nth 2 expr))) |
295 (t (cons (car expr) (mapcar 'math-map-over-constants-rec (cdr expr))))) | 282 (t (cons (car expr) (mapcar 'math-map-over-constants-rec (cdr expr)))))) |
296 ) | 283 |
297 | 284 ;;; calc-stuff.el ends here |
298 | |
299 | |
300 |