home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-31 | 55.2 KB | 1,884 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i070: gnucalc - GNU Emacs Calculator, v2.00, Part22/56
- Message-ID: <1991Oct31.072701.18039@sparky.imd.sterling.com>
- X-Md4-Signature: de49189cd5559a325671d1b2159a017c
- Date: Thu, 31 Oct 1991 07:27:01 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 70
- Archive-name: gnucalc/part22
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc-math.el continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 22; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc-math.el'
- else
- echo 'x - continuing file calc-math.el'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc-math.el' &&
- X x)
- X (t (calc-record-why 'numberp x)
- X (list 'calcFunc-arccosh x)))
- )
- (put 'calcFunc-arccosh 'math-expandable t)
- X
- (defun calcFunc-arctanh (x) ; [N N] [Public]
- X (cond ((eq x 0) 0)
- X ((and (Math-equal-int x 1) calc-infinite-mode)
- X '(var inf var-inf))
- X ((and (Math-equal-int x -1) calc-infinite-mode)
- X '(neg (var inf var-inf)))
- X (math-expand-formulas
- X (list '/ (list '-
- X (list 'calcFunc-ln (list '+ 1 x))
- X (list 'calcFunc-ln (list '- 1 x))) 2))
- X ((Math-numberp x)
- X (if calc-symbolic-mode (signal 'inexact-result nil))
- X (math-with-extra-prec 2
- X (if (or (memq (car-safe x) '(cplx polar))
- X (Math-lessp 1 x))
- X (math-mul (math-sub (math-ln-raw (math-add '(float 1 0) x))
- X (math-ln-raw (math-sub '(float 1 0) x)))
- X '(float 5 -1))
- X (if (and (math-equal-int x 1) calc-infinite-mode)
- X '(var inf var-inf)
- X (if (and (math-equal-int x -1) calc-infinite-mode)
- X '(neg (var inf var-inf))
- X (math-mul (math-ln-raw (math-div (math-add '(float 1 0) x)
- X (math-sub 1 x)))
- X '(float 5 -1)))))))
- X ((eq (car-safe x) 'sdev)
- X (math-make-sdev (calcFunc-arctanh (nth 1 x))
- X (math-div (nth 2 x)
- X (math-sub 1 (math-sqr (nth 1 x))))))
- X ((eq (car x) 'intv)
- X (math-sort-intv (nth 1 x)
- X (calcFunc-arctanh (nth 2 x))
- X (calcFunc-arctanh (nth 3 x))))
- X ((equal x '(var nan var-nan))
- X x)
- X (t (calc-record-why 'numberp x)
- X (list 'calcFunc-arctanh x)))
- )
- (put 'calcFunc-arctanh 'math-expandable t)
- X
- X
- ;;; Convert A from HMS or degrees to radians.
- (defun calcFunc-rad (a) ; [R R] [Public]
- X (cond ((or (Math-numberp a)
- X (eq (car a) 'intv))
- X (math-with-extra-prec 2
- X (math-mul a (math-pi-over-180))))
- X ((eq (car a) 'hms)
- X (math-from-hms a 'rad))
- X ((eq (car a) 'sdev)
- X (math-make-sdev (calcFunc-rad (nth 1 a))
- X (calcFunc-rad (nth 2 a))))
- X (math-expand-formulas
- X (math-div (math-mul a '(var pi var-pi)) 180))
- X ((math-infinitep a) a)
- X (t (list 'calcFunc-rad a)))
- )
- (put 'calcFunc-rad 'math-expandable t)
- X
- ;;; Convert A from HMS or radians to degrees.
- (defun calcFunc-deg (a) ; [R R] [Public]
- X (cond ((or (Math-numberp a)
- X (eq (car a) 'intv))
- X (math-with-extra-prec 2
- X (math-div a (math-pi-over-180))))
- X ((eq (car a) 'hms)
- X (math-from-hms a 'deg))
- X ((eq (car a) 'sdev)
- X (math-make-sdev (calcFunc-deg (nth 1 a))
- X (calcFunc-deg (nth 2 a))))
- X (math-expand-formulas
- X (math-div (math-mul 180 a) '(var pi var-pi)))
- X ((math-infinitep a) a)
- X (t (list 'calcFunc-deg a)))
- )
- (put 'calcFunc-deg 'math-expandable t)
- X
- X
- X
- X
- SHAR_EOF
- echo 'File calc-math.el is complete' &&
- chmod 0644 calc-math.el ||
- echo 'restore of calc-math.el failed'
- Wc_c="`wc -c < 'calc-math.el'`"
- test 52594 -eq "$Wc_c" ||
- echo 'calc-math.el: original size 52594, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= calc-misc.el ==============
- if test -f 'calc-misc.el' -a X"$1" != X"-c"; then
- echo 'x - skipping calc-misc.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting calc-misc.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'calc-misc.el' &&
- ;; Calculator for GNU Emacs, part I [calc-misc.el]
- ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
- ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
- X
- ;; This file is part of GNU Emacs.
- X
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
- X
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
- X
- X
- X
- ;; This file is autoloaded from calc.el.
- (require 'calc)
- X
- (require 'calc-macs)
- X
- (defun calc-Need-calc-misc () nil)
- X
- X
- (defun calc-dispatch-help (arg)
- X "M-# is a prefix key; follow it with one of these letters:
- X
- For turning Calc on and off:
- X C calc. Start the Calculator in a window at the bottom of the screen.
- X O calc-other-window. Start the Calculator but don't select its window.
- X B calc-big-or-small. Control whether to use the full Emacs screen for Calc.
- X Q quick-calc. Use the Calculator in the minibuffer.
- X K calc-keypad. Start the Calculator in keypad mode (X window system only).
- X E calc-embedded. Use the Calculator on a formula in this editing buffer.
- X J calc-embedded-select. Like E, but select appropriate half of => or :=.
- X W calc-embedded-word. Like E, but activate a single word, i.e., a number.
- X Z calc-user-invocation. Invoke Calc in the way you defined with `Z I' cmd.
- X X calc-quit. Turn Calc off.
- X
- For moving data into and out of Calc:
- X G calc-grab-region. Grab the region defined by mark and point into Calc.
- X R calc-grab-rectangle. Grab the rectangle defined by mark, point into Calc.
- X Y calc-copy-to-buffer. Copy a value from the stack into the editing buffer.
- X : calc-grab-sum-down. Grab a rectangle and sum the columns.
- X _ calc-grab-sum-across. Grab a rectangle and sum the rows.
- X
- For use with Embedded mode:
- X A calc-embedded-activate. Find and activate all :='s and =>'s in buffer.
- X D calc-embedded-duplicate. Make a copy of this formula and select it.
- X F calc-embedded-new-formula. Insert a new formula at current point.
- X N calc-embedded-next. Advance cursor to next known formula in buffer.
- X P calc-embedded-previous. Advance cursor to previous known formula.
- X U calc-embedded-update-formula. Re-evaluate formula at point.
- X ` calc-embedded-edit. Use calc-edit to edit formula at point.
- X
- Documentation:
- X I calc-info. Read the Calculator manual in the Emacs Info system.
- X T calc-tutorial. Run the Calculator Tutorial using the Emacs Info system.
- X S calc-summary. Read the Summary from the Calculator manual in Info.
- X
- Miscellaneous:
- X L calc-load-everything. Load all parts of the Calculator into memory.
- X M read-kbd-macro. Read a region of keystroke names as a keyboard macro.
- X 0 (zero) calc-reset. Reset Calc stack and modes to default state.
- X
- Press twice (`M-# M-#' or `M-# #') to turn Calc on or off using the same
- Calc user interface as before (either M-# C or M-# K; initially M-# C)."
- X (interactive "P")
- X (calc-check-defines)
- X (if calc-dispatch-help
- X (progn
- X (save-window-excursion
- X (describe-function 'calc-dispatch-help)
- X (let ((win (get-buffer-window "*Help*")))
- X (if win
- X (let (key)
- X (select-window win)
- X (while (progn
- X (message "Calc options: Calc, Keypad, ... %s"
- X "press SPC, DEL to scroll, C-g to cancel")
- X (memq (setq key (read-char))
- X '(? ?\C-h ?\C-? ?\C-v ?\M-v)))
- X (condition-case err
- X (if (memq key '(? ?\C-v))
- X (scroll-up)
- X (scroll-down))
- X (error (beep))))
- X (setq unread-command-char key)))))
- X (calc-do-dispatch nil))
- X (let ((calc-dispatch-help t))
- X (calc-do-dispatch arg)))
- )
- X
- X
- (defun calc-big-or-small (arg)
- X "Toggle Calc between full-screen and regular mode."
- X (interactive "P")
- X (let ((cwin (get-buffer-window "*Calculator*"))
- X (twin (get-buffer-window "*Calc Trail*"))
- X (kwin (get-buffer-window "*Calc Keypad*")))
- X (if cwin
- X (setq calc-full-mode
- X (if kwin
- X (and twin (eq (window-width twin) (screen-width)))
- X (eq (window-height cwin) (1- (screen-height))))))
- X (setq calc-full-mode (if arg
- X (> (prefix-numeric-value arg) 0)
- X (not calc-full-mode)))
- X (if kwin
- X (progn
- X (calc-quit)
- X (calc-do-keypad calc-full-mode nil))
- X (if cwin
- X (progn
- X (calc-quit)
- X (calc nil calc-full-mode nil))))
- X (message (if calc-full-mode
- X "Now using full screen for Calc."
- X "Now using partial screen for Calc.")))
- )
- X
- (defun calc-other-window ()
- X "Invoke the Calculator in another window."
- X (interactive)
- X (if (memq major-mode '(calc-mode calc-trail-mode))
- X (progn
- X (other-window 1)
- X (if (memq major-mode '(calc-mode calc-trail-mode))
- X (other-window 1)))
- X (if (get-buffer-window "*Calculator*")
- X (calc-quit)
- X (let ((win (selected-window)))
- X (calc nil win (interactive-p)))))
- )
- X
- (defun another-calc ()
- X "Create another, independent Calculator buffer."
- X (interactive)
- X (if (eq major-mode 'calc-mode)
- X (mapcar (function
- X (lambda (v)
- X (set-default v (symbol-value v)))) calc-local-var-list))
- X (set-buffer (generate-new-buffer "*Calculator*"))
- X (pop-to-buffer (current-buffer))
- X (calc-mode)
- )
- X
- X
- ;;; Make an attempt to preserve the window configuration, while deleting
- ;;; windows on "bufs". Emacs 19's delete-window function will probably
- ;;; make this kludgery unnecessary, but Emacs 18's tendency to grow all
- ;;; windows on the screen to take up the slack from the deleted windows
- ;;; can be annoying when Calc was called during another multi-window
- ;;; application, such as GNUS.
- X
- (defun calc-delete-windows-keep (&rest bufs)
- X (if (one-window-p)
- X (mapcar 'delete-windows-on bufs)
- X (let* ((w (car calc-was-split))
- X (e (window-edges w))
- X (wins nil)
- X w2 e2)
- X (while (progn
- X (setq w2 (previous-window w)
- X e2 (window-edges w2))
- X (and (= (car e2) (car e))
- X (= (nth 2 e2) (nth 2 e))
- X (< (nth 1 e2) (nth 1 e))))
- X (setq w w2 e e2))
- X (setq w2 w e2 e)
- X (while (progn
- X (setq wins (cons (list w (nth 1 e) (window-buffer w)
- X (window-point w) (window-start w))
- X wins)
- X w (next-window w)
- X e (window-edges w))
- X (and (not (eq w w2))
- X (= (car e2) (car e))
- X (= (nth 2 e2) (nth 2 e)))))
- X (setq wins (nreverse wins))
- X (mapcar 'delete-windows-on bufs)
- X (or (one-window-p)
- X (let ((w wins)
- X (main nil)
- X (mainpos 0)
- X (sel (if (window-point (nth 2 calc-was-split))
- X (nth 2 calc-was-split)
- X (selected-window))))
- X (while w
- X (if (window-point (car (car w)))
- X (if main
- X (delete-window (car (car w)))
- X (setq main (car (car w))
- X mainpos (nth 1 (car w))
- X wins (cdr wins)))
- X (setq wins (delq (car w) wins)))
- X (setq w (cdr w)))
- X (while wins
- X (setq w (split-window main
- X (if (eq main (car calc-was-split))
- X (nth 1 calc-was-split)
- X (- (nth 1 (car wins)) mainpos))))
- X (set-window-buffer w (nth 2 (car wins)))
- X (set-window-point w (nth 3 (car wins)))
- X (set-window-start w (nth 4 (car wins)))
- X (if (eq sel (car (car wins)))
- X (select-window w))
- X (setq main w
- X mainpos (nth 1 (car wins))
- X wins (cdr wins)))
- X (if (window-point sel)
- X (select-window sel))))))
- )
- X
- X
- (defun calc-info ()
- X "Run the Emacs Info system on the Calculator documentation."
- X (interactive)
- X (require 'info)
- X (select-window (get-largest-window))
- X (or (file-name-absolute-p calc-info-filename)
- X (let ((p load-path)
- X name)
- X (if (boundp 'Info-directory)
- X (setq p (cons Info-directory p)))
- X (while (and p (not (file-exists-p
- X (setq name (expand-file-name calc-info-filename
- X (car p))))))
- X (setq p (cdr p)))
- X (if p (setq calc-info-filename name))))
- X (info)
- X (or (and (boundp 'Info-current-file)
- X (stringp Info-current-file)
- X (string-match "calc" Info-current-file))
- X (Info-find-node calc-info-filename "Top"))
- )
- X
- (defun calc-tutorial ()
- X "Run the Emacs Info system on the Calculator Tutorial."
- X (interactive)
- X (if (get-buffer-window "*Calculator*")
- X (calc-quit))
- X (calc-info)
- X (Info-goto-node "Interactive Tutorial")
- X (calc-other-window)
- X (message "Welcome to the Calc Tutorial!")
- )
- X
- (defun calc-info-summary ()
- X "Run the Emacs Info system on the Calculator Summary."
- X (interactive)
- X (calc-info)
- X (Info-goto-node "Summary")
- )
- X
- (defun calc-help ()
- X (interactive)
- X (let ((msgs
- X '("Press `h' for complete help; press `?' repeatedly for a summary"
- X "Letter keys: Negate; Precision; Yank; Why; Xtended cmd; Quit"
- X "Letter keys: SHIFT + Undo, reDo; Keep-args; Inverse, Hyperbolic"
- X "Letter keys: SHIFT + sQrt; Sin, Cos, Tan; Exp, Ln, logB"
- X "Letter keys: SHIFT + Floor, Round; Abs, conJ, arG; Pi"
- X "Letter keys: SHIFT + Num-eval; More-recn; eXec-kbd-macro"
- X "Other keys: +, -, *, /, ^, \\ (int div), : (frac div)"
- X "Other keys: & (1/x), | (concat), % (modulo), ! (factorial)"
- X "Other keys: ' (alg-entry), = (eval), ` (edit); M-RET (last-args)"
- X "Other keys: SPC/RET (enter/dup), LFD (over); < > (scroll horiz)"
- X "Other keys: DEL (drop), M-DEL (drop-above); { } (scroll vert)"
- X "Other keys: TAB (swap/roll-dn), M-TAB (roll-up)"
- X "Other keys: [ , ; ] (vector), ( , ) (complex), ( ; ) (polar)"
- X "Prefix keys: Algebra, Binary/business, Convert, Display"
- X "Prefix keys: Functions, Graphics, Help, J (select)"
- X "Prefix keys: Kombinatorics/statistics, Modes, Store/recall"
- X "Prefix keys: Trail/time, Units/statistics, Vector/matrix"
- X "Prefix keys: Z (user), SHIFT + Z (define)"
- X "Prefix keys: prefix + ? gives further help for that prefix"
- X " Calc 2.00 by Dave Gillespie, daveg@csvax.cs.caltech.edu")))
- X (if calc-full-help-flag
- X msgs
- X (if (or calc-inverse-flag calc-hyperbolic-flag)
- X (if calc-inverse-flag
- X (if calc-hyperbolic-flag
- X (calc-inv-hyp-prefix-help)
- X (calc-inverse-prefix-help))
- X (calc-hyperbolic-prefix-help))
- X (setq calc-help-phase
- X (if (eq this-command last-command)
- X (% (1+ calc-help-phase) (1+ (length msgs)))
- X 0))
- X (let ((msg (nth calc-help-phase msgs)))
- X (message "%s" (if msg
- X (concat msg ":"
- X (make-string (- (apply 'max
- X (mapcar 'length
- X msgs))
- X (length msg)) 32)
- X " [?=MORE]")
- X ""))))))
- )
- X
- X
- X
- X
- ;;;; Stack and buffer management.
- X
- X
- (defun calc-do-handle-whys ()
- X (setq calc-why (sort calc-next-why
- X (function
- X (lambda (x y)
- X (and (eq (car x) '*) (not (eq (car y) '*))))))
- X calc-next-why nil)
- X (if (and calc-why (or (eq calc-auto-why t)
- X (and (eq (car (car calc-why)) '*)
- X calc-auto-why)))
- X (progn
- X (calc-extensions)
- X (calc-explain-why (car calc-why)
- X (if (eq calc-auto-why t)
- X (cdr calc-why)
- X (if calc-auto-why
- X (eq (car (nth 1 calc-why)) '*))))
- X (setq calc-last-why-command this-command)
- X (calc-clear-command-flag 'clear-message)))
- )
- X
- (defun calc-record-why (&rest stuff)
- X (if (eq (car stuff) 'quiet)
- X (setq stuff (cdr stuff))
- X (if (and (symbolp (car stuff))
- X (cdr stuff)
- X (or (Math-objectp (nth 1 stuff))
- X (and (Math-vectorp (nth 1 stuff))
- X (math-constp (nth 1 stuff)))
- X (math-infinitep (nth 1 stuff))))
- X (setq stuff (cons '* stuff))
- X (if (and (stringp (car stuff))
- X (string-match "\\`\\*" (car stuff)))
- X (setq stuff (cons '* (cons (substring (car stuff) 1)
- X (cdr stuff)))))))
- X (setq calc-next-why (cons stuff calc-next-why))
- X nil
- )
- X
- ;;; True if A is a constant or vector of constants. [P x] [Public]
- (defun math-constp (a)
- X (or (Math-scalarp a)
- X (and (memq (car a) '(sdev intv mod vec))
- X (progn
- X (while (and (setq a (cdr a))
- X (or (Math-scalarp (car a)) ; optimization
- X (math-constp (car a)))))
- X (null a))))
- )
- X
- X
- (defun calc-roll-down-stack (n &optional m)
- X (if (< n 0)
- X (calc-roll-up-stack (- n) m)
- X (if (or (= n 0) (> n (calc-stack-size))) (setq n (calc-stack-size)))
- X (or m (setq m 1))
- X (and (> n 1)
- X (< m n)
- X (if (and calc-any-selections
- X (not calc-use-selections))
- X (calc-roll-down-with-selections n m)
- X (calc-pop-push-list n
- X (append (calc-top-list m 1)
- X (calc-top-list (- n m) (1+ m)))))))
- )
- X
- (defun calc-roll-up-stack (n &optional m)
- X (if (< n 0)
- X (calc-roll-down-stack (- n) m)
- X (if (or (= n 0) (> n (calc-stack-size))) (setq n (calc-stack-size)))
- X (or m (setq m 1))
- X (and (> n 1)
- X (< m n)
- X (if (and calc-any-selections
- X (not calc-use-selections))
- X (calc-roll-up-with-selections n m)
- X (calc-pop-push-list n
- X (append (calc-top-list (- n m) 1)
- X (calc-top-list m (- n m -1)))))))
- )
- X
- X
- (defun calc-do-refresh ()
- X (if calc-hyperbolic-flag
- X (progn
- X (setq calc-display-dirty t)
- X nil)
- X (calc-refresh)
- X t)
- )
- X
- X
- (defun calc-record-list (vals &optional prefix)
- X (while vals
- X (or (eq (car vals) 'top-of-stack)
- X (progn
- X (calc-record (car vals) prefix)
- X (setq prefix "...")))
- X (setq vals (cdr vals)))
- )
- X
- X
- (defun calc-last-args-stub (arg)
- X (interactive "p")
- X (calc-extensions)
- X (calc-last-args arg)
- )
- X
- X
- (defun calc-power (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (if (and calc-extensions-loaded
- X (calc-is-inverse))
- X (calc-binary-op "root" 'calcFunc-nroot arg nil nil)
- X (calc-binary-op "^" 'calcFunc-pow arg nil nil '^)))
- )
- X
- (defun calc-mod (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-binary-op "%" 'calcFunc-mod arg nil nil '%))
- )
- X
- (defun calc-inv (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-unary-op "inv" 'calcFunc-inv arg))
- )
- X
- X
- (defun calc-over (n)
- X (interactive "P")
- X (if n
- X (calc-enter (- (prefix-numeric-value n)))
- X (calc-enter -2))
- )
- X
- X
- (defun calc-pop-above (n)
- X (interactive "P")
- X (if n
- X (calc-pop (- (prefix-numeric-value n)))
- X (calc-pop -2))
- )
- X
- (defun calc-roll-down (n)
- X (interactive "P")
- X (calc-wrapper
- X (let ((nn (prefix-numeric-value n)))
- X (cond ((null n)
- X (calc-roll-down-stack 2))
- X ((> nn 0)
- X (calc-roll-down-stack nn))
- X ((= nn 0)
- X (calc-pop-push-list (calc-stack-size)
- X (reverse
- X (calc-top-list (calc-stack-size)))))
- X (t
- X (calc-roll-down-stack (calc-stack-size) (- nn))))))
- )
- X
- (defun calc-roll-up (n)
- X (interactive "P")
- X (calc-wrapper
- X (let ((nn (prefix-numeric-value n)))
- X (cond ((null n)
- X (calc-roll-up-stack 3))
- X ((> nn 0)
- X (calc-roll-up-stack nn))
- X ((= nn 0)
- X (calc-pop-push-list (calc-stack-size)
- X (reverse
- X (calc-top-list (calc-stack-size)))))
- X (t
- X (calc-roll-up-stack (calc-stack-size) (- nn))))))
- )
- X
- X
- X
- X
- ;;; Other commands.
- X
- (defun calc-num-prefix-name (n)
- X (cond ((eq n '-) "- ")
- X ((equal n '(4)) "C-u ")
- X ((consp n) (format "%d " (car n)))
- X ((integerp n) (format "%d " n))
- X (t ""))
- )
- X
- (defun calc-missing-key (n)
- X "This is a placeholder for a command which needs to be loaded from calc-ext.
- When this key is used, calc-ext (the Calculator extensions module) will be
- loaded and the keystroke automatically re-typed."
- X (interactive "P")
- X (calc-extensions)
- X (if (keymapp (key-binding (char-to-string last-command-char)))
- X (message "%s%c-" (calc-num-prefix-name n) last-command-char))
- X (setq unread-command-char last-command-char
- X prefix-arg n)
- )
- X
- (defun calc-shift-Y-prefix-help ()
- X (interactive)
- X (calc-extensions)
- X (calc-do-prefix-help calc-Y-help-msgs "other" ?Y)
- )
- X
- X
- X
- X
- (defun calcDigit-letter ()
- X (interactive)
- X (if (calc-minibuffer-contains "[-+]?\\(1[1-9]\\|[2-9][0-9]\\)#.*")
- X (progn
- X (setq last-command-char (upcase last-command-char))
- X (calcDigit-key))
- X (calcDigit-nondigit))
- )
- X
- X
- ;; A Lisp version of temp_minibuffer_message from minibuf.c.
- (defun calc-temp-minibuffer-message (m)
- X (let ((savemax (point-max)))
- X (save-excursion
- X (goto-char (point-max))
- X (insert m))
- X (let ((okay nil))
- X (unwind-protect
- X (progn
- X (sit-for 2)
- X (identity 1) ; this forces a call to QUIT; in bytecode.c.
- X (setq okay t))
- X (progn
- X (delete-region savemax (point-max))
- X (or okay (abort-recursive-edit))))))
- )
- X
- X
- (put 'math-with-extra-prec 'lisp-indent-hook 1)
- X
- X
- ;;; Concatenate two vectors, or a vector and an object. [V O O] [Public]
- (defun math-concat (v1 v2)
- X (if (stringp v1)
- X (concat v1 v2)
- X (calc-extensions)
- X (if (and (or (math-objvecp v1) (math-known-scalarp v1))
- X (or (math-objvecp v2) (math-known-scalarp v2)))
- X (append (if (and (math-vectorp v1)
- X (or (math-matrixp v1)
- X (not (math-matrixp v2))))
- X v1
- X (list 'vec v1))
- X (if (and (math-vectorp v2)
- X (or (math-matrixp v2)
- X (not (math-matrixp v1))))
- X (cdr v2)
- X (list v2)))
- X (list '| v1 v2)))
- )
- X
- X
- ;;; True if A is zero. Works for un-normalized values. [P n] [Public]
- (defun math-zerop (a)
- X (if (consp a)
- X (cond ((memq (car a) '(bigpos bigneg))
- X (while (eq (car (setq a (cdr a))) 0))
- X (null a))
- X ((memq (car a) '(frac float polar mod))
- X (math-zerop (nth 1 a)))
- X ((eq (car a) 'cplx)
- X (and (math-zerop (nth 1 a)) (math-zerop (nth 2 a))))
- X ((eq (car a) 'hms)
- X (and (math-zerop (nth 1 a))
- X (math-zerop (nth 2 a))
- X (math-zerop (nth 3 a)))))
- X (eq a 0))
- )
- X
- X
- ;;; True if A is real and negative. [P n] [Public]
- X
- (defun math-negp (a)
- X (if (consp a)
- X (cond ((eq (car a) 'bigpos) nil)
- X ((eq (car a) 'bigneg) (cdr a))
- X ((memq (car a) '(float frac))
- X (Math-integer-negp (nth 1 a)))
- X ((eq (car a) 'hms)
- X (if (math-zerop (nth 1 a))
- X (if (math-zerop (nth 2 a))
- X (math-negp (nth 3 a))
- X (math-negp (nth 2 a)))
- X (math-negp (nth 1 a))))
- X ((eq (car a) 'date)
- X (math-negp (nth 1 a)))
- X ((eq (car a) 'intv)
- X (or (math-negp (nth 3 a))
- X (and (math-zerop (nth 3 a))
- X (memq (nth 1 a) '(0 2)))))
- X ((equal a '(neg (var inf var-inf))) t))
- X (< a 0))
- )
- X
- ;;; True if A is a negative number or an expression the starts with '-'.
- (defun math-looks-negp (a) ; [P x] [Public]
- X (or (Math-negp a)
- X (eq (car-safe a) 'neg)
- X (and (memq (car-safe a) '(* /))
- X (or (math-looks-negp (nth 1 a))
- X (math-looks-negp (nth 2 a))))
- X (and (eq (car-safe a) '-)
- X (math-looks-negp (nth 1 a))))
- )
- X
- X
- ;;; True if A is real and positive. [P n] [Public]
- (defun math-posp (a)
- X (if (consp a)
- X (cond ((eq (car a) 'bigpos) (cdr a))
- X ((eq (car a) 'bigneg) nil)
- X ((memq (car a) '(float frac))
- X (Math-integer-posp (nth 1 a)))
- X ((eq (car a) 'hms)
- X (if (math-zerop (nth 1 a))
- X (if (math-zerop (nth 2 a))
- X (math-posp (nth 3 a))
- X (math-posp (nth 2 a)))
- X (math-posp (nth 1 a))))
- X ((eq (car a) 'date)
- X (math-posp (nth 1 a)))
- X ((eq (car a) 'mod)
- X (not (math-zerop (nth 1 a))))
- X ((eq (car a) 'intv)
- X (or (math-posp (nth 2 a))
- X (and (math-zerop (nth 2 a))
- X (memq (nth 1 a) '(0 1)))))
- X ((equal a '(var inf var-inf)) t))
- X (> a 0))
- )
- X
- (fset 'math-fixnump (symbol-function 'integerp))
- (fset 'math-fixnatnump (symbol-function 'natnump))
- X
- X
- ;;; True if A is an even integer. [P R R] [Public]
- (defun math-evenp (a)
- X (if (consp a)
- X (and (memq (car a) '(bigpos bigneg))
- X (= (% (nth 1 a) 2) 0))
- X (= (% a 2) 0))
- )
- X
- ;;; Compute A / 2, for small or big integer A. [I i]
- ;;; If A is negative, type of truncation is undefined.
- (defun math-div2 (a)
- X (if (consp a)
- X (if (cdr a)
- X (math-normalize (cons (car a) (math-div2-bignum (cdr a))))
- X 0)
- X (/ a 2))
- )
- X
- (defun math-div2-bignum (a) ; [l l]
- X (if (cdr a)
- X (cons (+ (/ (car a) 2) (* (% (nth 1 a) 2) 500))
- X (math-div2-bignum (cdr a)))
- X (list (/ (car a) 2)))
- )
- X
- X
- ;;; Reject an argument to a calculator function. [Public]
- (defun math-reject-arg (&optional a p option)
- X (if option
- X (calc-record-why option p a)
- X (if p
- X (calc-record-why p a)))
- X (signal 'wrong-type-argument (and a (if p (list p a) (list a))))
- )
- X
- X
- ;;; Coerce A to be an integer (by truncation toward zero). [I N] [Public]
- (defun math-trunc (a &optional prec)
- X (cond (prec
- X (calc-extensions)
- X (math-trunc-special a prec))
- X ((Math-integerp a) a)
- X ((Math-looks-negp a)
- X (math-neg (math-trunc (math-neg a))))
- X ((eq (car a) 'float)
- X (math-scale-int (nth 1 a) (nth 2 a)))
- X (t (calc-extensions)
- X (math-trunc-fancy a)))
- )
- (fset 'calcFunc-trunc (symbol-function 'math-trunc))
- X
- ;;; Coerce A to be an integer (by truncation toward minus infinity). [I N]
- (defun math-floor (a &optional prec) ; [Public]
- X (cond (prec
- X (calc-extensions)
- X (math-floor-special a prec))
- X ((Math-integerp a) a)
- X ((Math-messy-integerp a) (math-trunc a))
- X ((Math-realp a)
- X (if (Math-negp a)
- X (math-add (math-trunc a) -1)
- X (math-trunc a)))
- X (t (calc-extensions)
- X (math-floor-fancy a)))
- )
- (fset 'calcFunc-floor (symbol-function 'math-floor))
- X
- X
- (defun math-imod (a b) ; [I I I] [Public]
- X (if (and (not (consp a)) (not (consp b)))
- X (if (= b 0)
- X (math-reject-arg a "*Division by zero")
- X (% a b))
- X (cdr (math-idivmod a b)))
- )
- X
- X
- (defun calcFunc-inv (m)
- X (if (Math-vectorp m)
- X (progn
- X (calc-extensions)
- X (if (math-square-matrixp m)
- X (or (math-with-extra-prec 2 (math-matrix-inv-raw m))
- X (math-reject-arg m "*Singular matrix"))
- X (math-reject-arg m 'square-matrixp)))
- X (math-div 1 m))
- )
- X
- X
- (defun math-do-working (msg arg)
- X (or executing-macro
- X (progn
- X (calc-set-command-flag 'clear-message)
- X (if math-working-step
- X (if math-working-step-2
- X (setq msg (format "[%d/%d] %s"
- X math-working-step math-working-step-2 msg))
- X (setq msg (format "[%d] %s" math-working-step msg))))
- X (message "Working... %s = %s" msg
- X (math-showing-full-precision (math-format-number arg)))))
- )
- X
- X
- ;;; Compute A modulo B, defined in terms of truncation toward minus infinity.
- (defun math-mod (a b) ; [R R R] [Public]
- X (cond ((and (Math-zerop a) (not (eq (car-safe a) 'mod))) a)
- X ((Math-zerop b)
- X (math-reject-arg a "*Division by zero"))
- X ((and (Math-natnump a) (Math-natnump b))
- X (math-imod a b))
- X ((and (Math-anglep a) (Math-anglep b))
- X (math-sub a (math-mul (math-floor (math-div a b)) b)))
- X (t (calc-extensions)
- X (math-mod-fancy a b)))
- )
- X
- X
- X
- ;;; General exponentiation.
- X
- (defun math-pow (a b) ; [O O N] [Public]
- X (cond ((equal b '(var nan var-nan))
- X b)
- X ((Math-zerop a)
- X (if (and (Math-scalarp b) (Math-posp b))
- X (if (math-floatp b) (math-float a) a)
- X (calc-extensions)
- X (math-pow-of-zero a b)))
- X ((or (eq a 1) (eq b 1)) a)
- X ((or (equal a '(float 1 0)) (equal b '(float 1 0))) a)
- X ((Math-zerop b)
- X (if (Math-scalarp a)
- X (if (or (math-floatp a) (math-floatp b))
- X '(float 1 0) 1)
- X (calc-extensions)
- X (math-pow-zero a b)))
- X ((and (Math-integerp b) (or (Math-numberp a) (Math-vectorp a)))
- X (if (and (equal a '(float 1 1)) (integerp b))
- X (math-make-float 1 b)
- X (math-with-extra-prec 2
- X (math-ipow a b))))
- X (t
- X (calc-extensions)
- X (math-pow-fancy a b)))
- )
- X
- (defun math-ipow (a n) ; [O O I] [Public]
- X (cond ((Math-integer-negp n)
- X (math-ipow (math-div 1 a) (Math-integer-neg n)))
- X ((not (consp n))
- X (if (and (Math-ratp a) (> n 20))
- X (math-iipow-show a n)
- X (math-iipow a n)))
- X ((math-evenp n)
- X (math-ipow (math-mul a a) (math-div2 n)))
- X (t
- X (math-mul a (math-ipow (math-mul a a)
- X (math-div2 (math-add n -1))))))
- )
- X
- (defun math-iipow (a n) ; [O O S]
- X (cond ((= n 0) 1)
- X ((= n 1) a)
- X ((= (% n 2) 0) (math-iipow (math-mul a a) (/ n 2)))
- X (t (math-mul a (math-iipow (math-mul a a) (/ n 2)))))
- )
- X
- (defun math-iipow-show (a n) ; [O O S]
- X (math-working "pow" a)
- X (let ((val (cond
- X ((= n 0) 1)
- X ((= n 1) a)
- X ((= (% n 2) 0) (math-iipow-show (math-mul a a) (/ n 2)))
- X (t (math-mul a (math-iipow-show (math-mul a a) (/ n 2)))))))
- X (math-working "pow" val)
- X val)
- )
- X
- X
- (defun math-read-radix-digit (dig) ; [D S; Z S]
- X (if (> dig ?9)
- X (if (< dig ?A)
- X nil
- X (- dig 55))
- X (if (>= dig ?0)
- X (- dig ?0)
- X nil))
- )
- X
- X
- X
- X
- X
- ;;; Bug reporting
- X
- (defun report-calc-bug (topic)
- X "Report a bug in Calc, the GNU Emacs calculator.
- Prompts for bug subject. Leaves you in a mail buffer."
- X (interactive "sBug Subject: ")
- X (mail nil calc-bug-address topic)
- X (goto-char (point-max))
- X (insert "\nIn Calc " calc-version ", Emacs " (emacs-version) "\n\n")
- X (message (substitute-command-keys "Type \\[mail-send] to send bug report."))
- )
- (fset 'calc-report-bug (symbol-function 'report-calc-bug))
- X
- SHAR_EOF
- chmod 0644 calc-misc.el ||
- echo 'restore of calc-misc.el failed'
- Wc_c="`wc -c < 'calc-misc.el'`"
- test 24690 -eq "$Wc_c" ||
- echo 'calc-misc.el: original size 24690, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= calc-mode.el ==============
- if test -f 'calc-mode.el' -a X"$1" != X"-c"; then
- echo 'x - skipping calc-mode.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting calc-mode.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'calc-mode.el' &&
- ;; Calculator for GNU Emacs, part II [calc-mode.el]
- ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
- ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
- X
- ;; This file is part of GNU Emacs.
- X
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
- X
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
- X
- X
- X
- ;; This file is autoloaded from calc-ext.el.
- (require 'calc-ext)
- X
- (require 'calc-macs)
- X
- (defun calc-Need-calc-mode () nil)
- X
- X
- (defun calc-line-numbering (n)
- X (interactive "P")
- X (calc-wrapper
- X (message (if (calc-change-mode 'calc-line-numbering n t t)
- X "Displaying stack level numbers."
- X "Hiding stack level numbers.")))
- )
- X
- (defun calc-line-breaking (n)
- X (interactive "P")
- X (calc-wrapper
- X (setq n (if n
- X (and (> (setq n (prefix-numeric-value n)) 0)
- X (or (< n 5)
- X n))
- X (not calc-line-breaking)))
- X (if (calc-change-mode 'calc-line-breaking n t)
- X (if (integerp calc-line-breaking)
- X (message "Breaking lines longer than %d characters." n)
- X (message "Breaking long lines in Stack display."))
- X (message "Not breaking long lines in Stack display.")))
- )
- X
- X
- (defun calc-left-justify (n)
- X (interactive "P")
- X (calc-wrapper
- X (and n (setq n (prefix-numeric-value n)))
- X (calc-change-mode '(calc-display-just calc-display-origin)
- X (list nil n) t)
- X (if n
- X (message "Displaying stack entries indented by %d." n)
- X (message "Displaying stack entries left-justified.")))
- )
- X
- (defun calc-center-justify (n)
- X (interactive "P")
- X (calc-wrapper
- X (and n (setq n (prefix-numeric-value n)))
- X (calc-change-mode '(calc-display-just calc-display-origin)
- X (list 'center n) t)
- X (if n
- X (message "Displaying stack entries centered on column %d." n)
- X (message "Displaying stack entries centered in window.")))
- )
- X
- (defun calc-right-justify (n)
- X (interactive "P")
- X (calc-wrapper
- X (and n (setq n (prefix-numeric-value n)))
- X (calc-change-mode '(calc-display-just calc-display-origin)
- X (list 'right n) t)
- X (if n
- X (message "Displaying stack entries right-justified to column %d." n)
- X (message "Displaying stack entries right-justified in window.")))
- )
- X
- (defun calc-left-label (s)
- X (interactive "sLefthand label: ")
- X (calc-wrapper
- X (or (equal s "")
- X (setq s (concat s " ")))
- X (calc-change-mode 'calc-left-label s t))
- )
- X
- (defun calc-right-label (s)
- X (interactive "sRighthand label: ")
- X (calc-wrapper
- X (or (equal s "")
- X (setq s (concat " " s)))
- X (calc-change-mode 'calc-right-label s t))
- )
- X
- (defun calc-auto-why (n)
- X (interactive "P")
- X (calc-wrapper
- X (if n
- X (progn
- X (setq n (prefix-numeric-value n))
- X (if (<= n 0) (setq n nil)
- X (if (> n 1) (setq n t))))
- X (setq n (and (not (eq calc-auto-why t)) (if calc-auto-why t 1))))
- X (calc-change-mode 'calc-auto-why n nil)
- X (cond ((null n)
- X (message "User must press `w' to explain unsimplified results."))
- X ((eq n t)
- X (message "Automatically doing `w' to explain unsimplified results."))
- X (t
- X (message "Automatically doing `w' only for unusual messages."))))
- )
- X
- (defun calc-group-digits (n)
- X (interactive "P")
- X (calc-wrapper
- X (if n
- X (progn
- X (setq n (prefix-numeric-value n))
- X (cond ((or (> n 0) (< n -1)))
- X ((= n -1)
- X (setq n nil))
- X (t
- X (setq n calc-group-digits))))
- X (setq n (not calc-group-digits)))
- X (calc-change-mode 'calc-group-digits n t)
- X (cond ((null n)
- X (message "Grouping is off."))
- X ((integerp n)
- X (message "Grouping every %d digits." (math-abs n)))
- X (t
- X (message "Grouping is on."))))
- )
- X
- (defun calc-group-char (ch)
- X (interactive "cGrouping character: ")
- X (calc-wrapper
- X (or (>= ch 32)
- X (error "Control characters not allowed for grouping."))
- X (if (= ch ?\\)
- X (setq ch "\\,")
- X (setq ch (char-to-string ch)))
- X (calc-change-mode 'calc-group-char ch calc-group-digits)
- X (message "Digit grouping character is \"%s\"." ch))
- )
- X
- (defun calc-point-char (ch)
- X (interactive "cCharacter to use as decimal point: ")
- X (calc-wrapper
- X (or (>= ch 32)
- X (error "Control characters not allowed as decimal point."))
- X (calc-change-mode 'calc-point-char (char-to-string ch) t)
- X (message "Decimal point character is \"%c\"." ch))
- )
- X
- (defun calc-normal-notation (n)
- X (interactive "P")
- X (calc-wrapper
- X (calc-change-mode 'calc-float-format
- X (setq n (list 'float (if n (prefix-numeric-value n) 0)))
- X t)
- X (if (eq (nth 1 n) 0)
- X (message "Displaying floating-point numbers normally.")
- X (if (> (nth 1 n) 0)
- X (message
- X "Displaying floating-point numbers with %d significant digits."
- X (nth 1 n))
- X (message "Displaying floating-point numbers with (precision%d)."
- X (nth 1 n)))))
- )
- X
- (defun calc-fix-notation (n)
- X (interactive "NDigits after decimal point: ")
- X (calc-wrapper
- X (calc-change-mode 'calc-float-format
- X (setq n (list 'fix (if n (prefix-numeric-value n) 0)))
- X t)
- X (message "Displaying floats with %d digits after decimal."
- X (math-abs (nth 1 n))))
- )
- X
- (defun calc-sci-notation (n)
- X (interactive "P")
- X (calc-wrapper
- X (calc-change-mode 'calc-float-format
- X (setq n (list 'sci (if n (prefix-numeric-value n) 0)))
- X t)
- X (if (eq (nth 1 n) 0)
- X (message "Displaying floats in scientific notation.")
- X (if (> (nth 1 n) 0)
- X (message "Displaying scientific notation with %d significant digits."
- X (nth 1 n))
- X (message "Displaying scientific notation with (precision%d)."
- X (nth 1 n)))))
- )
- X
- (defun calc-eng-notation (n)
- X (interactive "P")
- X (calc-wrapper
- X (calc-change-mode 'calc-float-format
- X (setq n (list 'eng (if n (prefix-numeric-value n) 0)))
- X t)
- X (if (eq (nth 1 n) 0)
- X (message "Displaying floats in engineering notation.")
- X (if (> (nth 1 n) 0)
- X (message "Displaying engineering notation with %d significant digits."
- X (nth 1 n))
- X (message "Displaying engineering notation with (precision%d)."
- X (nth 1 n)))))
- )
- X
- X
- (defun calc-truncate-stack (n &optional rel)
- X (interactive "P")
- X (calc-wrapper
- X (let ((oldtop calc-stack-top)
- X (newtop calc-stack-top))
- X (calc-record-undo (list 'set 'saved-stack-top calc-stack-top))
- X (let ((calc-stack-top 0)
- X (nn (prefix-numeric-value n)))
- X (setq newtop
- X (if n
- X (progn
- X (if rel
- X (setq nn (+ oldtop nn))
- X (if (< nn 0)
- X (setq nn (+ nn (calc-stack-size)))
- X (setq nn (1+ nn))))
- X (if (< nn 1)
- X 1
- X (if (> nn (calc-stack-size))
- X (calc-stack-size)
- X nn)))
- X (max 1 (calc-locate-cursor-element (point)))))
- X (if (= newtop oldtop)
- X ()
- X (calc-pop-stack 1 oldtop t)
- X (calc-push-list '(top-of-stack) newtop)
- X (if calc-line-numbering
- X (calc-refresh))))
- X (calc-record-undo (list 'set 'saved-stack-top 0))
- X (setq calc-stack-top newtop)))
- )
- X
- (defun calc-truncate-up (n)
- X (interactive "p")
- X (calc-truncate-stack n t)
- )
- X
- (defun calc-truncate-down (n)
- X (interactive "p")
- X (calc-truncate-stack (- n) t)
- )
- X
- (defun calc-display-raw (arg)
- X (interactive "P")
- X (calc-wrapper
- X (setq calc-display-raw (if calc-display-raw nil (if arg 0 t)))
- X (calc-do-refresh)
- X (if calc-display-raw
- X (message "Press d ' again to cancel \"raw\" display mode.")))
- )
- X
- X
- X
- X
- ;;; Mode commands.
- X
- (defun calc-save-modes (&optional quiet)
- X (interactive)
- X (calc-wrapper
- X (let (pos
- X (vals (mapcar (function (lambda (v) (symbol-value (car v))))
- X calc-mode-var-list)))
- X (set-buffer (find-file-noselect (substitute-in-file-name
- X calc-settings-file)))
- X (goto-char (point-min))
- X (if (and (search-forward ";;; Mode settings stored by Calc" nil t)
- X (progn
- X (beginning-of-line)
- X (setq pos (point))
- X (search-forward "\n;;; End of mode settings" nil t)))
- X (progn
- X (beginning-of-line)
- X (forward-line 1)
- X (delete-region pos (point)))
- X (goto-char (point-max))
- X (insert "\n\n")
- X (forward-char -1))
- X (insert ";;; Mode settings stored by Calc on " (current-time-string) "\n")
- X (let ((list calc-mode-var-list))
- X (while list
- X (let* ((v (car (car list)))
- X (def (nth 1 (car list)))
- X (val (car vals)))
- X (or (equal val def)
- X (progn
- X (insert "(setq " (symbol-name v) " ")
- X (if (and (or (listp val)
- X (symbolp val))
- X (not (memq val '(nil t))))
- X (insert "'"))
- X (insert (prin1-to-string val) ")\n"))))
- X (setq list (cdr list)
- X vals (cdr vals))))
- X (run-hooks 'calc-mode-save-hook)
- X (insert ";;; End of mode settings\n")
- X (if quiet
- X (let ((executing-macro "")) ; what a kludge!
- X (save-buffer))
- X (save-buffer))))
- )
- X
- (defun calc-settings-file-name (name &optional arg)
- X (interactive "sSettings file name (normally ~/.emacs): \nP")
- X (calc-wrapper
- X (setq arg (if arg (prefix-numeric-value arg) 0))
- X (if (equal name "")
- X (message "Calc settings file is \"%s\"" calc-settings-file)
- X (if (< (math-abs arg) 2)
- X (let ((list calc-mode-var-list))
- X (while list
- X (set (car (car list)) (nth 1 (car list)))
- X (setq list (cdr list)))))
- X (setq calc-settings-file name)
- X (or (and (string-match "\\.emacs" calc-settings-file)
- X (> arg 0))
- X (< arg 0)
- X (load name t)
- X (message "New file"))))
- )
- X
- (defun calc-shift-prefix (arg)
- X (interactive "P")
- X (calc-wrapper
- X (setq calc-shift-prefix (if arg
- X (> (prefix-numeric-value arg) 0)
- X (not calc-shift-prefix)))
- X (calc-init-prefixes)
- X (message (if calc-shift-prefix
- X "Prefix keys are now case-insensitive"
- X "Prefix keys must be unshifted (except V, Z)")))
- )
- X
- (defun calc-mode-record-mode (n)
- X (interactive "P")
- X (calc-wrapper
- X (calc-change-mode 'calc-mode-save-mode
- X (cond ((null n)
- X (cond ((not calc-embedded-info)
- X (if (eq calc-mode-save-mode 'save)
- X 'local 'save))
- X ((eq calc-mode-save-mode 'local) 'edit)
- X ((eq calc-mode-save-mode 'edit) 'perm)
- X ((eq calc-mode-save-mode 'perm) 'global)
- X ((eq calc-mode-save-mode 'global) 'save)
- X ((eq calc-mode-save-mode 'save) nil)
- X ((eq calc-mode-save-mode nil) 'local)))
- X ((= (setq n (prefix-numeric-value n)) 0) nil)
- X ((= n 2) 'edit)
- X ((= n 3) 'perm)
- X ((= n 4) 'global)
- X ((= n 5) 'save)
- X (t 'local)))
- X (message (cond ((and (eq calc-mode-save-mode 'local) calc-embedded-info)
- X "Recording mode changes with [calc-mode: ...]")
- X ((eq calc-mode-save-mode 'edit)
- X "Recording mode changes with [calc-edit-mode: ...]")
- X ((eq calc-mode-save-mode 'perm)
- X "Recording mode changes with [calc-perm-mode: ...]")
- X ((eq calc-mode-save-mode 'global)
- X "Recording mode changes with [calc-global-mode: ...]")
- X ((eq calc-mode-save-mode 'save)
- X (format "Recording mode changes in \"%s\"."
- X calc-settings-file))
- X (t
- X "Not recording mode changes permanently."))))
- )
- X
- (defun calc-total-algebraic-mode (flag)
- X (interactive "P")
- X (calc-wrapper
- X (if (eq calc-algebraic-mode 'total)
- X (calc-algebraic-mode nil)
- X (calc-change-mode '(calc-algebraic-mode calc-incomplete-algebraic-mode)
- X '(total nil))
- X (use-local-map calc-alg-map)
- X (message
- X "All keys begin algebraic entry; use Meta (ESC) for Calc keys.")))
- )
- X
- (defun calc-algebraic-mode (flag)
- X (interactive "P")
- X (calc-wrapper
- X (if flag
- X (calc-change-mode '(calc-algebraic-mode
- X calc-incomplete-algebraic-mode)
- X (list nil (not calc-incomplete-algebraic-mode)))
- X (calc-change-mode '(calc-algebraic-mode calc-incomplete-algebraic-mode)
- X (list (not calc-algebraic-mode) nil)))
- X (use-local-map calc-mode-map)
- X (message (if calc-algebraic-mode
- X "Numeric keys and ( and [ begin algebraic entry."
- X (if calc-incomplete-algebraic-mode
- X "Only ( and [ begin algebraic entry."
- X "No keys except ' and $ begin algebraic entry."))))
- )
- X
- (defun calc-symbolic-mode (n)
- X (interactive "P")
- X (calc-wrapper
- X
- X (message (if (calc-change-mode 'calc-symbolic-mode n nil t)
- X "Inexact computations like sqrt(2) are deferred."
- X "Numerical computations are always done immediately.")))
- )
- X
- (defun calc-infinite-mode (n)
- X (interactive "P")
- X (calc-wrapper
- X (if (eq n 0)
- X (progn
- X (calc-change-mode 'calc-infinite-mode 1)
- X (message "Computations like 1 / 0 produce \"inf\"."))
- X (message (if (calc-change-mode 'calc-infinite-mode n nil t)
- X "Computations like 1 / 0 produce \"uinf\"."
- X "Computations like 1 / 0 are left unsimplified."))))
- )
- X
- (defun calc-matrix-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-change-mode 'calc-matrix-mode
- X (cond ((eq arg 0) 'scalar)
- X ((< (prefix-numeric-value arg) 1)
- X (error "Dimension must be 1 or more"))
- X (arg (prefix-numeric-value arg))
- X ((eq calc-matrix-mode 'matrix) 'scalar)
- X ((eq calc-matrix-mode 'scalar) nil)
- X (t 'matrix)))
- X (if (integerp calc-matrix-mode)
- X (message "Variables are assumed to be %dx%d matrices."
- X calc-matrix-mode calc-matrix-mode)
- X (message (if (eq calc-matrix-mode 'matrix)
- X "Variables are assumed to be matrices."
- X (if calc-matrix-mode
- X "Variables are assumed to be scalars (non-matrices)."
- X "Variables are not assumed to be matrix or scalar.")))))
- )
- X
- (defun calc-set-simplify-mode (mode arg msg)
- X (calc-change-mode 'calc-simplify-mode
- X (if arg
- X (and (> (prefix-numeric-value arg) 0)
- X mode)
- X (and (not (eq calc-simplify-mode mode))
- X mode)))
- X (message (if (eq calc-simplify-mode mode)
- X msg
- X "Default simplifications enabled."))
- )
- X
- (defun calc-no-simplify-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-set-simplify-mode 'none arg
- X "All default simplifications are disabled."))
- )
- X
- (defun calc-num-simplify-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-set-simplify-mode 'num arg
- X "Default simplifications apply only if arguments are numeric."))
- )
- X
- (defun calc-default-simplify-mode ()
- X (interactive)
- X (calc-wrapper
- X (calc-set-simplify-mode nil nil "Usual default simplifications are enabled."))
- )
- X
- (defun calc-bin-simplify-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-set-simplify-mode 'binary arg
- X (format "Binary simplification occurs by default (word size=%d)."
- X calc-word-size)))
- )
- X
- (defun calc-alg-simplify-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-set-simplify-mode 'alg arg
- X "Algebraic simplification occurs by default."))
- )
- X
- (defun calc-ext-simplify-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-set-simplify-mode 'ext arg
- X "Extended algebraic simplification occurs by default."))
- )
- X
- (defun calc-units-simplify-mode (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-set-simplify-mode 'units arg
- X "Units simplification occurs by default."))
- )
- X
- (defun calc-auto-recompute (arg)
- X (interactive "P")
- X (calc-wrapper
- X (calc-change-mode 'calc-auto-recompute arg nil t)
- X (calc-refresh-evaltos)
- X (message (if calc-auto-recompute
- X "Automatically recomputing `=>' forms when necessary."
- X "Not recomputing `=>' forms automatically.")))
- )
- X
- (defun calc-working (n)
- X (interactive "P")
- X (calc-wrapper
- X (cond ((consp n)
- X (calc-pop-push-record 0 "work"
- X (cond ((eq calc-display-working-message t) 1)
- X (calc-display-working-message 2)
- X (t 0))))
- X ((eq n 2) (calc-change-mode 'calc-display-working-message 'lots))
- X ((eq n 0) (calc-change-mode 'calc-display-working-message nil))
- X ((eq n 1) (calc-change-mode 'calc-display-working-message t)))
- X (cond ((eq calc-display-working-message t)
- X (message "\"Working...\" messages enabled."))
- X (calc-display-working-message
- X (message "Detailed \"Working...\" messages enabled."))
- X (t
- X (message "\"Working...\" messages disabled."))))
- )
- X
- (defun calc-always-load-extensions ()
- X (interactive)
- X (calc-wrapper
- X (if (setq calc-always-load-extensions (not calc-always-load-extensions))
- X (message "Always loading extensions package.")
- X (message "Loading extensions package on demand only.")))
- )
- X
- X
- (defun calc-matrix-left-justify ()
- X (interactive)
- X (calc-wrapper
- X (calc-change-mode 'calc-matrix-just nil t)
- X (message "Matrix elements will be left-justified in columns."))
- )
- X
- (defun calc-matrix-center-justify ()
- X (interactive)
- X (calc-wrapper
- X (calc-change-mode 'calc-matrix-just 'center t)
- X (message "Matrix elements will be centered in columns."))
- )
- X
- (defun calc-matrix-right-justify ()
- X (interactive)
- X (calc-wrapper
- X (calc-change-mode 'calc-matrix-just 'right t)
- X (message "Matrix elements will be right-justified in columns."))
- )
- X
- (defun calc-full-vectors (n)
- X (interactive "P")
- X (calc-wrapper
- X (message (if (calc-change-mode 'calc-full-vectors n t t)
- X "Displaying long vectors in full."
- X "Displaying long vectors in [a, b, c, ..., z] notation.")))
- )
- X
- (defun calc-full-trail-vectors (n)
- X (interactive "P")
- X (calc-wrapper
- X (message (if (calc-change-mode 'calc-full-trail-vectors n nil t)
- X "Recording long vectors in full."
- X "Recording long vectors in [a, b, c, ..., z] notation.")))
- )
- X
- (defun calc-break-vectors (n)
- X (interactive "P")
- X (calc-wrapper
- X (message (if (calc-change-mode 'calc-break-vectors n t t)
- X "Displaying vector elements one-per-line."
- X "Displaying vector elements all on one line.")))
- )
- X
- (defun calc-vector-commas ()
- X (interactive)
- X (calc-wrapper
- X (if (calc-change-mode 'calc-vector-commas (if calc-vector-commas nil ",") t)
- X (message "Separating vector elements with \",\".")
- X (message "Separating vector elements with spaces.")))
- )
- X
- (defun calc-vector-brackets ()
- X (interactive)
- X (calc-wrapper
- X (if (calc-change-mode 'calc-vector-brackets
- X (if (equal calc-vector-brackets "[]") nil "[]") t)
- X (message "Surrounding vectors with \"[]\".")
- X (message "Not surrounding vectors with brackets.")))
- )
- X
- (defun calc-vector-braces ()
- X (interactive)
- X (calc-wrapper
- X (if (calc-change-mode 'calc-vector-brackets
- X (if (equal calc-vector-brackets "{}") nil "{}") t)
- X (message "Surrounding vectors with \"{}\".")
- X (message "Not surrounding vectors with brackets.")))
- )
- X
- (defun calc-vector-parens ()
- X (interactive)
- X (calc-wrapper
- X (if (calc-change-mode 'calc-vector-brackets
- X (if (equal calc-vector-brackets "()") nil "()") t)
- X (message "Surrounding vectors with \"()\".")
- X (message "Not surrounding vectors with brackets.")))
- )
- X
- (defun calc-matrix-brackets (arg)
- X (interactive "sCode letters (R, O, C, P): ")
- X (calc-wrapper
- X (let ((code (append (and (string-match "[rR]" arg) '(R))
- X (and (string-match "[oO]" arg) '(O))
- X (and (string-match "[cC]" arg) '(C))
- X (and (string-match "[pP]" arg) '(P))))
- X (bad (string-match "[^rRoOcCpP ]" arg)))
- X (if bad
- X (error "Unrecognized character: %c" (aref arg bad)))
- X (calc-change-mode 'calc-matrix-brackets code t)))
- )
- X
- SHAR_EOF
- chmod 0644 calc-mode.el ||
- echo 'restore of calc-mode.el failed'
- Wc_c="`wc -c < 'calc-mode.el'`"
- test 19361 -eq "$Wc_c" ||
- echo 'calc-mode.el: original size 19361, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= calc-poly.el ==============
- if test -f 'calc-poly.el' -a X"$1" != X"-c"; then
- echo 'x - skipping calc-poly.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting calc-poly.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'calc-poly.el' &&
- ;; Calculator for GNU Emacs, part II [calc-poly.el]
- ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
- ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
- X
- ;; This file is part of GNU Emacs.
- X
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
- X
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
- X
- X
- X
- ;; This file is autoloaded from calc-ext.el.
- (require 'calc-ext)
- X
- (require 'calc-macs)
- X
- (defun calc-Need-calc-poly () nil)
- X
- X
- (defun calcFunc-pcont (expr &optional var)
- X (cond ((Math-primp expr)
- X (cond ((Math-zerop expr) 1)
- X ((Math-messy-integerp expr) (math-trunc expr))
- X ((Math-objectp expr) expr)
- X ((or (equal expr var) (not var)) 1)
- X (t expr)))
- X ((eq (car expr) '*)
- X (math-mul (calcFunc-pcont (nth 1 expr) var)
- X (calcFunc-pcont (nth 2 expr) var)))
- X ((eq (car expr) '/)
- X (math-div (calcFunc-pcont (nth 1 expr) var)
- X (calcFunc-pcont (nth 2 expr) var)))
- X ((and (eq (car expr) '^) (Math-natnump (nth 2 expr)))
- X (math-pow (calcFunc-pcont (nth 1 expr) var) (nth 2 expr)))
- X ((memq (car expr) '(neg polar))
- X (calcFunc-pcont (nth 1 expr) var))
- X ((consp var)
- X (let ((p (math-is-polynomial expr var)))
- X (if p
- X (let ((lead (nth (1- (length p)) p))
- X (cont (math-poly-gcd-list p)))
- X (if (math-guess-if-neg lead)
- X (math-neg cont)
- X cont))
- X 1)))
- X ((memq (car expr) '(+ - cplx sdev))
- X (let ((cont (calcFunc-pcont (nth 1 expr) var)))
- X (if (eq cont 1)
- X 1
- X (let ((c2 (calcFunc-pcont (nth 2 expr) var)))
- X (if (and (math-negp cont)
- X (if (eq (car expr) '-) (math-posp c2) (math-negp c2)))
- X (math-neg (math-poly-gcd cont c2))
- X (math-poly-gcd cont c2))))))
- X (var expr)
- X (t 1))
- )
- X
- (defun calcFunc-pprim (expr &optional var)
- X (let ((cont (calcFunc-pcont expr var)))
- X (if (math-equal-int cont 1)
- X expr
- X (math-poly-div-exact expr cont var)))
- )
- X
- (defun math-div-poly-const (expr c)
- X (cond ((memq (car-safe expr) '(+ -))
- X (list (car expr)
- X (math-div-poly-const (nth 1 expr) c)
- X (math-div-poly-const (nth 2 expr) c)))
- X (t (math-div expr c)))
- )
- X
- (defun calcFunc-pdeg (expr &optional var)
- X (if (Math-zerop expr)
- X '(neg (var inf var-inf))
- X (if var
- X (or (math-polynomial-p expr var)
- X (math-reject-arg expr "Expected a polynomial"))
- X (math-poly-degree expr)))
- )
- X
- (defun math-poly-degree (expr)
- X (cond ((Math-primp expr)
- X (if (eq (car-safe expr) 'var) 1 0))
- X ((eq (car expr) 'neg)
- X (math-poly-degree (nth 1 expr)))
- X ((eq (car expr) '*)
- X (+ (math-poly-degree (nth 1 expr))
- X (math-poly-degree (nth 2 expr))))
- X ((eq (car expr) '/)
- X (- (math-poly-degree (nth 1 expr))
- X (math-poly-degree (nth 2 expr))))
- X ((and (eq (car expr) '^) (natnump (nth 2 expr)))
- X (* (math-poly-degree (nth 1 expr)) (nth 2 expr)))
- X ((memq (car expr) '(+ -))
- X (max (math-poly-degree (nth 1 expr))
- X (math-poly-degree (nth 2 expr))))
- X (t 1))
- )
- X
- (defun calcFunc-plead (expr var)
- X (cond ((eq (car-safe expr) '*)
- X (math-mul (calcFunc-plead (nth 1 expr) var)
- X (calcFunc-plead (nth 2 expr) var)))
- X ((eq (car-safe expr) '/)
- X (math-div (calcFunc-plead (nth 1 expr) var)
- X (calcFunc-plead (nth 2 expr) var)))
- X ((and (eq (car-safe expr) '^) (math-natnump (nth 2 expr)))
- X (math-pow (calcFunc-plead (nth 1 expr) var) (nth 2 expr)))
- X ((Math-primp expr)
- X (if (equal expr var)
- X 1
- X expr))
- X (t
- X (let ((p (math-is-polynomial expr var)))
- X (if (cdr p)
- X (nth (1- (length p)) p)
- X 1))))
- )
- X
- X
- X
- X
- X
- ;;; Polynomial quotient, remainder, and GCD.
- ;;; Originally by Ove Ewerlid (ewerlid@mizar.DoCS.UU.SE).
- ;;; Modifications and simplifications by daveg.
- X
- (setq math-poly-modulus 1)
- X
- ;;; Return gcd of two polynomials
- (defun calcFunc-pgcd (pn pd)
- X (if (math-any-floats pn)
- X (math-reject-arg pn "Coefficients must be rational"))
- X (if (math-any-floats pd)
- X (math-reject-arg pd "Coefficients must be rational"))
- X (let ((calc-prefer-frac t)
- X (math-poly-modulus (math-poly-modulus pn pd)))
- X (math-poly-gcd pn pd))
- )
- X
- ;;; Return only quotient to top of stack (nil if zero)
- (defun calcFunc-pdiv (pn pd &optional base)
- X (let* ((calc-prefer-frac t)
- X (math-poly-modulus (math-poly-modulus pn pd))
- X (res (math-poly-div pn pd base)))
- X (setq calc-poly-div-remainder (cdr res))
- X (car res))
- )
- X
- ;;; Return only remainder to top of stack
- (defun calcFunc-prem (pn pd &optional base)
- X (let ((calc-prefer-frac t)
- X (math-poly-modulus (math-poly-modulus pn pd)))
- X (cdr (math-poly-div pn pd base)))
- )
- X
- (defun calcFunc-pdivrem (pn pd &optional base)
- X (let* ((calc-prefer-frac t)
- X (math-poly-modulus (math-poly-modulus pn pd))
- X (res (math-poly-div pn pd base)))
- X (list 'vec (car res) (cdr res)))
- )
- X
- (defun calcFunc-pdivide (pn pd &optional base)
- X (let* ((calc-prefer-frac t)
- X (math-poly-modulus (math-poly-modulus pn pd))
- X (res (math-poly-div pn pd base)))
- X (math-add (car res) (math-div (cdr res) pd)))
- SHAR_EOF
- true || echo 'restore of calc-poly.el failed'
- fi
- echo 'End of part 22'
- echo 'File calc-poly.el is continued in part 23'
- echo 23 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-