1 ;; Calculator for GNU Emacs, part II [calc-incom.el]
2 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 ;; Written by Dave Gillespie, daveg@synaptics.com.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is distributed in the hope that it will be useful,
8 ;; but WITHOUT ANY WARRANTY. No author or distributor
9 ;; accepts responsibility to anyone for the consequences of using it
10 ;; or for whether it serves any particular purpose or works at all,
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public
12 ;; License for full details.
14 ;; Everyone is granted permission to copy, modify and redistribute
15 ;; GNU Emacs, but only under the conditions described in the
16 ;; GNU Emacs General Public License. A copy of this license is
17 ;; supposed to have been given to you along with GNU Emacs so you
18 ;; can know your rights and responsibilities. It should be in a
19 ;; file named COPYING. Among other things, the copyright notice
20 ;; and this notice must be preserved on all copies.
24 ;; This file is autoloaded from calc-ext.el.
29 (defun calc-Need-calc-incom () nil)
34 (defun calc-begin-complex ()
37 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode)
39 (calc-push (list 'incomplete calc-complex-mode))))
42 (defun calc-end-complex ()
46 (let ((top (calc-top 1)))
47 (if (and (eq (car-safe top) 'incomplete)
48 (eq (nth 1 top) 'intv))
50 (if (< (length top) 4)
51 (setq top (append top '((neg (var inf var-inf))))))
52 (if (< (length top) 5)
53 (setq top (append top '((var inf var-inf)))))
54 (calc-enter-result 1 "..)" (cdr top)))
55 (if (not (and (eq (car-safe top) 'incomplete)
56 (memq (nth 1 top) '(cplx polar))))
57 (error "Not entering a complex number"))
58 (while (< (length top) 4)
59 (setq top (append top '(0))))
60 (if (not (and (math-realp (nth 2 top))
61 (math-anglep (nth 3 top))))
62 (error "Components must be real"))
63 (calc-enter-result 1 "()" (cdr top)))))
66 (defun calc-begin-vector ()
69 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode)
71 (calc-push '(incomplete vec))))
74 (defun calc-end-vector ()
78 (let ((top (calc-top 1)))
79 (if (and (eq (car-safe top) 'incomplete)
80 (eq (nth 1 top) 'intv))
82 (if (< (length top) 4)
83 (setq top (append top '((neg (var inf var-inf))))))
84 (if (< (length top) 5)
85 (setq top (append top '((var inf var-inf)))))
86 (setcar (cdr (cdr top)) (1+ (nth 2 top)))
87 (calc-enter-result 1 "..]" (cdr top)))
88 (if (not (and (eq (car-safe top) 'incomplete)
89 (eq (nth 1 top) 'vec)))
90 (error "Not entering a vector"))
91 (calc-pop-push-record 1 "[]" (cdr top)))))
94 (defun calc-comma (&optional allow-polar)
97 (let ((num (calc-find-first-incomplete
98 (nthcdr calc-stack-top calc-stack) 1)))
100 (error "Not entering a vector or complex number"))
101 (let* ((inc (calc-top num))
102 (stuff (calc-top-list (1- num)))
103 (new (append inc stuff)))
104 (if (and (null stuff)
106 (or (eq (nth 1 inc) 'vec)
108 (setq new (append new
109 (if (= (length new) 2)
111 (nthcdr (1- (length new)) new)))))
113 (if (eq (nth 1 new) 'polar)
114 (setq new (append '(incomplete cplx) (cdr (cdr new))))
115 (if (eq (nth 1 new) 'intv)
116 (setq new (append '(incomplete cplx)
117 (cdr (cdr (cdr new))))))))
118 (if (and (memq (nth 1 new) '(cplx polar))
120 (error "Too many components in complex number"))
121 (if (and (eq (nth 1 new) 'intv)
123 (error "Too many components in interval form"))
124 (calc-pop-push num new))))
130 (let ((num (calc-find-first-incomplete
131 (nthcdr calc-stack-top calc-stack) 1)))
133 (error "Not entering a vector or complex number"))
134 (let ((inc (calc-top num))
135 (stuff (calc-top-list (1- num))))
136 (if (eq (nth 1 inc) 'cplx)
137 (setq inc (append '(incomplete polar) (cdr (cdr inc))))
138 (if (eq (nth 1 inc) 'intv)
139 (setq inc (append '(incomplete polar) (cdr (cdr (cdr inc)))))))
140 (cond ((eq (nth 1 inc) 'polar)
141 (let ((new (append inc stuff)))
142 (if (> (length new) 4)
143 (error "Too many components in complex number")
144 (if (= (length new) 2)
145 (setq new (append new '(1)))))
146 (calc-pop-push num new)))
148 (if (> (length inc) 2)
149 (if (math-vectorp (nth 2 inc))
152 (list 'incomplete 'vec (cdr (cdr inc)))
153 (list 'incomplete 'vec)))))
154 ((math-vectorp (car stuff))
156 ((eq (car-safe (car-safe (nth (+ num calc-stack-top)
157 calc-stack))) 'incomplete)
160 (let ((calc-algebraic-mode nil)
161 (calc-incomplete-algebraic-mode nil))
162 (calc-begin-vector)))
163 ((or (= (length inc) 2)
164 (math-vectorp (nth 2 inc)))
166 (append inc (list (cons 'vec stuff)))
167 (list 'incomplete 'vec)))
170 (list 'incomplete 'vec
171 (cons 'vec (append (cdr (cdr inc)) stuff)))
172 (list 'incomplete 'vec)))))))
175 (defun calc-digit-dots ()
176 (if (eq calc-prev-char ?.)
178 (delete-backward-char 1)
179 (if (calc-minibuffer-contains ".*\\.\\'")
180 (delete-backward-char 1))
181 (setq calc-prev-char 'dots
182 last-command-char ? )
183 (if calc-prev-prev-char
185 (setq calc-digit-value nil)
188 ;; just ignore extra decimal point, anticipating ".."
189 (delete-backward-char 1))
195 (let ((num (calc-find-first-incomplete
196 (nthcdr calc-stack-top calc-stack) 1)))
198 (error "Not entering an interval form"))
199 (let* ((inc (calc-top num))
200 (stuff (calc-top-list (1- num)))
201 (new (append inc stuff)))
202 (if (not (eq (nth 1 new) 'intv))
203 (setq new (append '(incomplete intv)
204 (if (eq (nth 1 new) 'vec) '(2) '(0))
206 (if (and (null stuff)
208 (setq new (append new '((neg (var inf var-inf))))))
209 (if (> (length new) 5)
210 (error "Too many components in interval form"))
211 (calc-pop-push num new))))
214 (defun calc-find-first-incomplete (stack n)
217 ((eq (car-safe (car-safe (car stack))) 'incomplete)
220 (calc-find-first-incomplete (cdr stack) (1+ n))))
223 (defun calc-incomplete-error (a)
224 (cond ((memq (nth 1 a) '(cplx polar))
225 (error "Complex number is incomplete"))
227 (error "Vector is incomplete"))
228 ((eq (nth 1 a) 'intv)
229 (error "Interval form is incomplete"))
230 (t (error "Object is incomplete")))