1 ;;; calc-incom.el --- complex data type input functions for Calc
3 ;; Copyright (C) 1990-1993, 2001-2015 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file is autoloaded from calc-ext.el.
34 (defun calc-begin-complex ()
37 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode
)
39 (calc-push (list 'incomplete calc-complex-mode
)))))
41 (defun calc-end-complex ()
45 (let ((top (calc-top 1)))
46 (if (and (eq (car-safe top
) 'incomplete
)
47 (eq (nth 1 top
) 'intv
))
49 (if (< (length top
) 4)
50 (setq top
(append top
'((neg (var inf var-inf
))))))
51 (if (< (length top
) 5)
52 (setq top
(append top
'((var inf var-inf
)))))
53 (calc-enter-result 1 "..)" (cdr top
)))
54 (if (not (and (eq (car-safe top
) 'incomplete
)
55 (memq (nth 1 top
) '(cplx polar
))))
56 (error "Not entering a complex number"))
57 (while (< (length top
) 4)
58 (setq top
(append top
'(0))))
59 (if (not (and (math-realp (nth 2 top
))
60 (math-anglep (nth 3 top
))))
61 (error "Components must be real"))
62 (calc-enter-result 1 "()" (cdr top
))))))
64 (defun calc-begin-vector ()
67 (if (or calc-algebraic-mode calc-incomplete-algebraic-mode
)
69 (calc-push '(incomplete vec
)))))
71 (defun calc-end-vector ()
75 (let ((top (calc-top 1)))
76 (if (and (eq (car-safe top
) 'incomplete
)
77 (eq (nth 1 top
) 'intv
))
79 (if (< (length top
) 4)
80 (setq top
(append top
'((neg (var inf var-inf
))))))
81 (if (< (length top
) 5)
82 (setq top
(append top
'((var inf var-inf
)))))
83 (setcar (cdr (cdr top
)) (1+ (nth 2 top
)))
84 (calc-enter-result 1 "..]" (cdr top
)))
85 (if (not (and (eq (car-safe top
) 'incomplete
)
86 (eq (nth 1 top
) 'vec
)))
87 (error "Not entering a vector"))
88 (calc-pop-push-record 1 "[]" (cdr top
))))))
90 (defun calc-comma (&optional allow-polar
)
93 (let ((num (calc-find-first-incomplete
94 (nthcdr calc-stack-top calc-stack
) 1)))
96 (error "Not entering a vector or complex number"))
97 (let* ((inc (calc-top num
))
98 (stuff (calc-top-list (1- num
)))
99 (new (append inc stuff
)))
100 (if (and (null stuff
)
102 (or (eq (nth 1 inc
) 'vec
)
104 (setq new
(append new
105 (if (= (length new
) 2)
107 (nthcdr (1- (length new
)) new
)))))
109 (if (eq (nth 1 new
) 'polar
)
110 (setq new
(append '(incomplete cplx
) (cdr (cdr new
))))
111 (if (eq (nth 1 new
) 'intv
)
112 (setq new
(append '(incomplete cplx
)
113 (cdr (cdr (cdr new
))))))))
114 (if (and (memq (nth 1 new
) '(cplx polar
))
116 (error "Too many components in complex number"))
117 (if (and (eq (nth 1 new
) 'intv
)
119 (error "Too many components in interval form"))
120 (calc-pop-push num new
)))))
125 (let ((num (calc-find-first-incomplete
126 (nthcdr calc-stack-top calc-stack
) 1)))
128 (error "Not entering a vector or complex number"))
129 (let ((inc (calc-top num
))
130 (stuff (calc-top-list (1- num
))))
131 (if (eq (nth 1 inc
) 'cplx
)
132 (setq inc
(append '(incomplete polar
) (cdr (cdr inc
))))
133 (if (eq (nth 1 inc
) 'intv
)
134 (setq inc
(append '(incomplete polar
) (cdr (cdr (cdr inc
)))))))
135 (cond ((eq (nth 1 inc
) 'polar
)
136 (let ((new (append inc stuff
)))
137 (if (> (length new
) 4)
138 (error "Too many components in complex number")
139 (if (= (length new
) 2)
140 (setq new
(append new
'(1)))))
141 (calc-pop-push num new
)))
143 (if (> (length inc
) 2)
144 (if (math-vectorp (nth 2 inc
))
147 (list 'incomplete
'vec
(cdr (cdr inc
)))
148 (list 'incomplete
'vec
)))))
149 ((math-vectorp (car stuff
))
151 ((eq (car-safe (car-safe (nth (+ num calc-stack-top
)
152 calc-stack
))) 'incomplete
)
155 (let ((calc-algebraic-mode nil
)
156 (calc-incomplete-algebraic-mode nil
))
157 (calc-begin-vector)))
158 ((or (= (length inc
) 2)
159 (math-vectorp (nth 2 inc
)))
161 (append inc
(list (cons 'vec stuff
)))
162 (list 'incomplete
'vec
)))
165 (list 'incomplete
'vec
166 (cons 'vec
(append (cdr (cdr inc
)) stuff
)))
167 (list 'incomplete
'vec
))))))))
169 ;; The following variables are initially declared in calc.el,
170 ;; but are used by calc-digit-dots.
171 (defvar calc-prev-char
)
172 (defvar calc-prev-prev-char
)
173 (defvar calc-digit-value
)
175 (defun calc-digit-dots ()
176 (if (eq calc-prev-char ?.
)
179 (if (calc-minibuffer-contains ".*\\.\\'")
181 (setq calc-prev-char
'dots
182 last-command-event
32)
183 (if calc-prev-prev-char
185 (setq calc-digit-value nil
)
186 (let ((inhibit-read-only t
))
189 ;; just ignore extra decimal point, anticipating ".."
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
)))))
213 (defun calc-find-first-incomplete (stack n
)
216 ((eq (car-safe (car-safe (car stack
))) 'incomplete
)
219 (calc-find-first-incomplete (cdr stack
) (1+ n
)))))
221 (defun calc-incomplete-error (a)
222 (cond ((memq (nth 1 a
) '(cplx polar
))
223 (error "Complex number is incomplete"))
225 (error "Vector is incomplete"))
226 ((eq (nth 1 a
) 'intv
)
227 (error "Interval form is incomplete"))
228 (t (error "Object is incomplete"))))
230 (provide 'calc-incom
)
232 ;;; calc-incom.el ends here