Mercurial > emacs
annotate lisp/calc/calc-math.el @ 90180:62afea0771d8
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-51
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 289-301)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 68)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 12 May 2005 03:41:19 +0000 |
parents | bf0d492ea2d5 a27ed02e5a65 |
children | 187d6a1f84f7 |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
1 ;;; calc-math.el --- mathematical functions for Calc |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
2 |
62165
a27ed02e5a65
Update copyright year.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60164
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2005 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
58663
7ed196c06460
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58475
diff
changeset
|
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 ;; accepts responsibility to anyone for the consequences of using it | |
13 ;; or for whether it serves any particular purpose or works at all, | |
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 ;; License for full details. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; GNU Emacs General Public License. A copy of this license is | |
20 ;; supposed to have been given to you along with GNU Emacs so you | |
21 ;; can know your rights and responsibilities. It should be in a | |
22 ;; file named COPYING. Among other things, the copyright notice | |
23 ;; and this notice must be preserved on all copies. | |
24 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
25 ;;; Commentary: |
40785 | 26 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 ;; This file is autoloaded from calc-ext.el. | |
58663
7ed196c06460
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58475
diff
changeset
|
30 |
40785 | 31 (require 'calc-ext) |
32 (require 'calc-macs) | |
33 | |
34 (defun calc-sqrt (arg) | |
35 (interactive "P") | |
36 (calc-slow-wrapper | |
37 (if (calc-is-inverse) | |
38 (calc-unary-op "^2" 'calcFunc-sqr arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
39 (calc-unary-op "sqrt" 'calcFunc-sqrt arg)))) |
40785 | 40 |
41 (defun calc-isqrt (arg) | |
42 (interactive "P") | |
43 (calc-slow-wrapper | |
44 (if (calc-is-inverse) | |
45 (calc-unary-op "^2" 'calcFunc-sqr arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
46 (calc-unary-op "isqt" 'calcFunc-isqrt arg)))) |
40785 | 47 |
48 | |
49 (defun calc-hypot (arg) | |
50 (interactive "P") | |
51 (calc-slow-wrapper | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
52 (calc-binary-op "hypt" 'calcFunc-hypot arg))) |
40785 | 53 |
54 (defun calc-ln (arg) | |
55 (interactive "P") | |
56 (calc-invert-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
57 (calc-exp arg)) |
40785 | 58 |
59 (defun calc-log10 (arg) | |
60 (interactive "P") | |
61 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
62 (calc-ln arg)) |
40785 | 63 |
64 (defun calc-log (arg) | |
65 (interactive "P") | |
66 (calc-slow-wrapper | |
67 (if (calc-is-inverse) | |
68 (calc-binary-op "alog" 'calcFunc-alog arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
69 (calc-binary-op "log" 'calcFunc-log arg)))) |
40785 | 70 |
71 (defun calc-ilog (arg) | |
72 (interactive "P") | |
73 (calc-slow-wrapper | |
74 (if (calc-is-inverse) | |
75 (calc-binary-op "alog" 'calcFunc-alog arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
76 (calc-binary-op "ilog" 'calcFunc-ilog arg)))) |
40785 | 77 |
78 (defun calc-lnp1 (arg) | |
79 (interactive "P") | |
80 (calc-invert-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
81 (calc-expm1 arg)) |
40785 | 82 |
83 (defun calc-exp (arg) | |
84 (interactive "P") | |
85 (calc-slow-wrapper | |
86 (if (calc-is-hyperbolic) | |
87 (if (calc-is-inverse) | |
88 (calc-unary-op "lg10" 'calcFunc-log10 arg) | |
89 (calc-unary-op "10^" 'calcFunc-exp10 arg)) | |
90 (if (calc-is-inverse) | |
91 (calc-unary-op "ln" 'calcFunc-ln arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
92 (calc-unary-op "exp" 'calcFunc-exp arg))))) |
40785 | 93 |
94 (defun calc-expm1 (arg) | |
95 (interactive "P") | |
96 (calc-slow-wrapper | |
97 (if (calc-is-inverse) | |
98 (calc-unary-op "ln+1" 'calcFunc-lnp1 arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
99 (calc-unary-op "ex-1" 'calcFunc-expm1 arg)))) |
40785 | 100 |
101 (defun calc-pi () | |
102 (interactive) | |
103 (calc-slow-wrapper | |
104 (if (calc-is-inverse) | |
105 (if (calc-is-hyperbolic) | |
106 (if calc-symbolic-mode | |
107 (calc-pop-push-record 0 "phi" '(var phi var-phi)) | |
108 (calc-pop-push-record 0 "phi" (math-phi))) | |
109 (if calc-symbolic-mode | |
110 (calc-pop-push-record 0 "gmma" '(var gamma var-gamma)) | |
111 (calc-pop-push-record 0 "gmma" (math-gamma-const)))) | |
112 (if (calc-is-hyperbolic) | |
113 (if calc-symbolic-mode | |
114 (calc-pop-push-record 0 "e" '(var e var-e)) | |
115 (calc-pop-push-record 0 "e" (math-e))) | |
116 (if calc-symbolic-mode | |
117 (calc-pop-push-record 0 "pi" '(var pi var-pi)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
118 (calc-pop-push-record 0 "pi" (math-pi))))))) |
40785 | 119 |
120 (defun calc-sin (arg) | |
121 (interactive "P") | |
122 (calc-slow-wrapper | |
123 (if (calc-is-hyperbolic) | |
124 (if (calc-is-inverse) | |
125 (calc-unary-op "asnh" 'calcFunc-arcsinh arg) | |
126 (calc-unary-op "sinh" 'calcFunc-sinh arg)) | |
127 (if (calc-is-inverse) | |
128 (calc-unary-op "asin" 'calcFunc-arcsin arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
129 (calc-unary-op "sin" 'calcFunc-sin arg))))) |
40785 | 130 |
131 (defun calc-arcsin (arg) | |
132 (interactive "P") | |
133 (calc-invert-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
134 (calc-sin arg)) |
40785 | 135 |
136 (defun calc-sinh (arg) | |
137 (interactive "P") | |
138 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
139 (calc-sin arg)) |
40785 | 140 |
141 (defun calc-arcsinh (arg) | |
142 (interactive "P") | |
143 (calc-invert-func) | |
144 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
145 (calc-sin arg)) |
40785 | 146 |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
147 (defun calc-sec (arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
148 (interactive "P") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
149 (calc-slow-wrapper |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
150 (if (calc-is-hyperbolic) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
151 (calc-unary-op "sech" 'calcFunc-sech arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
152 (calc-unary-op "sec" 'calcFunc-sec arg)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
153 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
154 (defun calc-sech (arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
155 (interactive "P") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
156 (calc-hyperbolic-func) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
157 (calc-sec arg)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
158 |
40785 | 159 (defun calc-cos (arg) |
160 (interactive "P") | |
161 (calc-slow-wrapper | |
162 (if (calc-is-hyperbolic) | |
163 (if (calc-is-inverse) | |
164 (calc-unary-op "acsh" 'calcFunc-arccosh arg) | |
165 (calc-unary-op "cosh" 'calcFunc-cosh arg)) | |
166 (if (calc-is-inverse) | |
167 (calc-unary-op "acos" 'calcFunc-arccos arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
168 (calc-unary-op "cos" 'calcFunc-cos arg))))) |
40785 | 169 |
170 (defun calc-arccos (arg) | |
171 (interactive "P") | |
172 (calc-invert-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
173 (calc-cos arg)) |
40785 | 174 |
175 (defun calc-cosh (arg) | |
176 (interactive "P") | |
177 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
178 (calc-cos arg)) |
40785 | 179 |
180 (defun calc-arccosh (arg) | |
181 (interactive "P") | |
182 (calc-invert-func) | |
183 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
184 (calc-cos arg)) |
40785 | 185 |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
186 (defun calc-csc (arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
187 (interactive "P") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
188 (calc-slow-wrapper |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
189 (if (calc-is-hyperbolic) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
190 (calc-unary-op "csch" 'calcFunc-csch arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
191 (calc-unary-op "csc" 'calcFunc-csc arg)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
192 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
193 (defun calc-csch (arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
194 (interactive "P") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
195 (calc-hyperbolic-func) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
196 (calc-csc arg)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
197 |
40785 | 198 (defun calc-sincos () |
199 (interactive) | |
200 (calc-slow-wrapper | |
201 (if (calc-is-inverse) | |
202 (calc-enter-result 1 "asnc" (list 'calcFunc-arcsincos (calc-top-n 1))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
203 (calc-enter-result 1 "sncs" (list 'calcFunc-sincos (calc-top-n 1)))))) |
40785 | 204 |
205 (defun calc-tan (arg) | |
206 (interactive "P") | |
207 (calc-slow-wrapper | |
208 (if (calc-is-hyperbolic) | |
209 (if (calc-is-inverse) | |
210 (calc-unary-op "atnh" 'calcFunc-arctanh arg) | |
211 (calc-unary-op "tanh" 'calcFunc-tanh arg)) | |
212 (if (calc-is-inverse) | |
213 (calc-unary-op "atan" 'calcFunc-arctan arg) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
214 (calc-unary-op "tan" 'calcFunc-tan arg))))) |
40785 | 215 |
216 (defun calc-arctan (arg) | |
217 (interactive "P") | |
218 (calc-invert-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
219 (calc-tan arg)) |
40785 | 220 |
221 (defun calc-tanh (arg) | |
222 (interactive "P") | |
223 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
224 (calc-tan arg)) |
40785 | 225 |
226 (defun calc-arctanh (arg) | |
227 (interactive "P") | |
228 (calc-invert-func) | |
229 (calc-hyperbolic-func) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
230 (calc-tan arg)) |
40785 | 231 |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
232 (defun calc-cot (arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
233 (interactive "P") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
234 (calc-slow-wrapper |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
235 (if (calc-is-hyperbolic) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
236 (calc-unary-op "coth" 'calcFunc-coth arg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
237 (calc-unary-op "cot" 'calcFunc-cot arg)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
238 |
60164
697e2ba683cc
(calc-arctan, calc-tanh, calc-arctanh): Removed extra definitions.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60085
diff
changeset
|
239 (defun calc-coth (arg) |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
240 (interactive "P") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
241 (calc-hyperbolic-func) |
60164
697e2ba683cc
(calc-arctan, calc-tanh, calc-arctanh): Removed extra definitions.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60085
diff
changeset
|
242 (calc-cot arg)) |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
243 |
40785 | 244 (defun calc-arctan2 () |
245 (interactive) | |
246 (calc-slow-wrapper | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
247 (calc-enter-result 2 "atn2" (cons 'calcFunc-arctan2 (calc-top-list-n 2))))) |
40785 | 248 |
249 (defun calc-conj (arg) | |
250 (interactive "P") | |
251 (calc-wrapper | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
252 (calc-unary-op "conj" 'calcFunc-conj arg))) |
40785 | 253 |
254 (defun calc-imaginary () | |
255 (interactive) | |
256 (calc-slow-wrapper | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
257 (calc-pop-push-record 1 "i*" (math-imaginary (calc-top-n 1))))) |
40785 | 258 |
259 (defun calc-to-degrees (arg) | |
260 (interactive "P") | |
261 (calc-wrapper | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
262 (calc-unary-op ">deg" 'calcFunc-deg arg))) |
40785 | 263 |
264 (defun calc-to-radians (arg) | |
265 (interactive "P") | |
266 (calc-wrapper | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
267 (calc-unary-op ">rad" 'calcFunc-rad arg))) |
40785 | 268 |
269 | |
270 (defun calc-degrees-mode (arg) | |
271 (interactive "p") | |
272 (cond ((= arg 1) | |
273 (calc-wrapper | |
274 (calc-change-mode 'calc-angle-mode 'deg) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
275 (message "Angles measured in degrees"))) |
40785 | 276 ((= arg 2) (calc-radians-mode)) |
277 ((= arg 3) (calc-hms-mode)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
278 (t (error "Prefix argument out of range")))) |
40785 | 279 |
280 (defun calc-radians-mode () | |
281 (interactive) | |
282 (calc-wrapper | |
283 (calc-change-mode 'calc-angle-mode 'rad) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
284 (message "Angles measured in radians"))) |
40785 | 285 |
286 | |
287 ;;; Compute the integer square-root floor(sqrt(A)). A > 0. [I I] [Public] | |
288 ;;; This method takes advantage of the fact that Newton's method starting | |
289 ;;; with an overestimate always works, even using truncating integer division! | |
290 (defun math-isqrt (a) | |
291 (cond ((Math-zerop a) a) | |
292 ((not (math-natnump a)) | |
293 (math-reject-arg a 'natnump)) | |
294 ((integerp a) | |
295 (math-isqrt-small a)) | |
296 (t | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
297 (math-normalize (cons 'bigpos (cdr (math-isqrt-bignum (cdr a)))))))) |
40785 | 298 |
299 (defun calcFunc-isqrt (a) | |
300 (if (math-realp a) | |
301 (math-isqrt (math-floor a)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
302 (math-floor (math-sqrt a)))) |
40785 | 303 |
304 | |
42206 | 305 ;;; This returns (flag . result) where the flag is t if A is a perfect square. |
40785 | 306 (defun math-isqrt-bignum (a) ; [P.l L] |
307 (let ((len (length a))) | |
308 (if (= (% len 2) 0) | |
309 (let* ((top (nthcdr (- len 2) a))) | |
310 (math-isqrt-bignum-iter | |
311 a | |
312 (math-scale-bignum-3 | |
313 (math-bignum-big | |
314 (1+ (math-isqrt-small | |
315 (+ (* (nth 1 top) 1000) (car top))))) | |
316 (1- (/ len 2))))) | |
317 (let* ((top (nth (1- len) a))) | |
318 (math-isqrt-bignum-iter | |
319 a | |
320 (math-scale-bignum-3 | |
321 (list (1+ (math-isqrt-small top))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
322 (/ len 2))))))) |
40785 | 323 |
324 (defun math-isqrt-bignum-iter (a guess) ; [l L l] | |
325 (math-working "isqrt" (cons 'bigpos guess)) | |
326 (let* ((q (math-div-bignum a guess)) | |
327 (s (math-add-bignum (car q) guess)) | |
328 (g2 (math-div2-bignum s)) | |
329 (comp (math-compare-bignum g2 guess))) | |
330 (if (< comp 0) | |
331 (math-isqrt-bignum-iter a g2) | |
332 (cons (and (= comp 0) | |
333 (math-zerop-bignum (cdr q)) | |
334 (= (% (car s) 2) 0)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
335 guess)))) |
40785 | 336 |
337 (defun math-zerop-bignum (a) | |
338 (and (eq (car a) 0) | |
339 (progn | |
340 (while (eq (car (setq a (cdr a))) 0)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
341 (null a)))) |
40785 | 342 |
343 (defun math-scale-bignum-3 (a n) ; [L L S] | |
344 (while (> n 0) | |
345 (setq a (cons 0 a) | |
346 n (1- n))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
347 a) |
40785 | 348 |
349 (defun math-isqrt-small (a) ; A > 0. [S S] | |
350 (let ((g (cond ((>= a 10000) 1000) | |
351 ((>= a 100) 100) | |
352 (t 10))) | |
353 g2) | |
354 (while (< (setq g2 (/ (+ g (/ a g)) 2)) g) | |
355 (setq g g2)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
356 g)) |
40785 | 357 |
358 | |
359 | |
360 | |
361 ;;; Compute the square root of a number. | |
362 ;;; [T N] if possible, else [F N] if possible, else [C N]. [Public] | |
363 (defun math-sqrt (a) | |
364 (or | |
365 (and (Math-zerop a) a) | |
366 (and (math-known-nonposp a) | |
367 (math-imaginary (math-sqrt (math-neg a)))) | |
368 (and (integerp a) | |
369 (let ((sqrt (math-isqrt-small a))) | |
370 (if (= (* sqrt sqrt) a) | |
371 sqrt | |
372 (if calc-symbolic-mode | |
373 (list 'calcFunc-sqrt a) | |
374 (math-sqrt-float (math-float a) (math-float sqrt)))))) | |
375 (and (eq (car-safe a) 'bigpos) | |
376 (let* ((res (math-isqrt-bignum (cdr a))) | |
377 (sqrt (math-normalize (cons 'bigpos (cdr res))))) | |
378 (if (car res) | |
379 sqrt | |
380 (if calc-symbolic-mode | |
381 (list 'calcFunc-sqrt a) | |
382 (math-sqrt-float (math-float a) (math-float sqrt)))))) | |
383 (and (eq (car-safe a) 'frac) | |
384 (let* ((num-res (math-isqrt-bignum (cdr (Math-bignum-test (nth 1 a))))) | |
385 (num-sqrt (math-normalize (cons 'bigpos (cdr num-res)))) | |
386 (den-res (math-isqrt-bignum (cdr (Math-bignum-test (nth 2 a))))) | |
387 (den-sqrt (math-normalize (cons 'bigpos (cdr den-res))))) | |
388 (if (and (car num-res) (car den-res)) | |
389 (list 'frac num-sqrt den-sqrt) | |
390 (if calc-symbolic-mode | |
391 (if (or (car num-res) (car den-res)) | |
392 (math-div (if (car num-res) | |
393 num-sqrt (list 'calcFunc-sqrt (nth 1 a))) | |
394 (if (car den-res) | |
395 den-sqrt (list 'calcFunc-sqrt (nth 2 a)))) | |
396 (list 'calcFunc-sqrt a)) | |
397 (math-sqrt-float (math-float a) | |
398 (math-div (math-float num-sqrt) den-sqrt)))))) | |
399 (and (eq (car-safe a) 'float) | |
400 (if calc-symbolic-mode | |
401 (if (= (% (nth 2 a) 2) 0) | |
402 (let ((res (math-isqrt-bignum | |
403 (cdr (Math-bignum-test (nth 1 a)))))) | |
404 (if (car res) | |
405 (math-make-float (math-normalize | |
406 (cons 'bigpos (cdr res))) | |
407 (/ (nth 2 a) 2)) | |
408 (signal 'inexact-result nil))) | |
409 (signal 'inexact-result nil)) | |
410 (math-sqrt-float a))) | |
411 (and (eq (car-safe a) 'cplx) | |
412 (math-with-extra-prec 2 | |
413 (let* ((d (math-abs a)) | |
414 (imag (math-sqrt (math-mul (math-sub d (nth 1 a)) | |
415 '(float 5 -1))))) | |
416 (list 'cplx | |
417 (math-sqrt (math-mul (math-add d (nth 1 a)) '(float 5 -1))) | |
418 (if (math-negp (nth 2 a)) (math-neg imag) imag))))) | |
419 (and (eq (car-safe a) 'polar) | |
420 (list 'polar | |
421 (math-sqrt (nth 1 a)) | |
422 (math-mul (nth 2 a) '(float 5 -1)))) | |
423 (and (eq (car-safe a) 'sdev) | |
424 (let ((sqrt (math-sqrt (nth 1 a)))) | |
425 (math-make-sdev sqrt | |
426 (math-div (nth 2 a) (math-mul sqrt 2))))) | |
427 (and (eq (car-safe a) 'intv) | |
428 (not (math-negp (nth 2 a))) | |
429 (math-make-intv (nth 1 a) (math-sqrt (nth 2 a)) (math-sqrt (nth 3 a)))) | |
430 (and (eq (car-safe a) '*) | |
431 (or (math-known-nonnegp (nth 1 a)) | |
432 (math-known-nonnegp (nth 2 a))) | |
433 (math-mul (math-sqrt (nth 1 a)) (math-sqrt (nth 2 a)))) | |
434 (and (eq (car-safe a) '/) | |
435 (or (and (math-known-nonnegp (nth 2 a)) | |
436 (math-div (math-sqrt (nth 1 a)) (math-sqrt (nth 2 a)))) | |
437 (and (math-known-nonnegp (nth 1 a)) | |
438 (not (math-equal-int (nth 1 a) 1)) | |
439 (math-mul (math-sqrt (nth 1 a)) | |
440 (math-sqrt (math-div 1 (nth 2 a))))))) | |
441 (and (eq (car-safe a) '^) | |
442 (math-known-evenp (nth 2 a)) | |
443 (math-known-realp (nth 1 a)) | |
444 (math-abs (math-pow (nth 1 a) (math-div (nth 2 a) 2)))) | |
445 (let ((inf (math-infinitep a))) | |
446 (and inf | |
447 (math-mul (math-sqrt (math-infinite-dir a inf)) inf))) | |
448 (progn | |
449 (calc-record-why 'numberp a) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
450 (list 'calcFunc-sqrt a)))) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
451 (defalias 'calcFunc-sqrt 'math-sqrt) |
40785 | 452 |
453 (defun math-infinite-dir (a &optional inf) | |
454 (or inf (setq inf (math-infinitep a))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
455 (math-normalize (math-expr-subst a inf 1))) |
40785 | 456 |
457 (defun math-sqrt-float (a &optional guess) ; [F F F] | |
458 (if calc-symbolic-mode | |
459 (signal 'inexact-result nil) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
460 (math-with-extra-prec 1 (math-sqrt-raw a guess)))) |
40785 | 461 |
462 (defun math-sqrt-raw (a &optional guess) ; [F F F] | |
463 (if (not (Math-posp a)) | |
464 (math-sqrt a) | |
465 (if (null guess) | |
466 (let ((ldiff (- (math-numdigs (nth 1 a)) 6))) | |
467 (or (= (% (+ (nth 2 a) ldiff) 2) 0) (setq ldiff (1+ ldiff))) | |
468 (setq guess (math-make-float (math-isqrt-small | |
469 (math-scale-int (nth 1 a) (- ldiff))) | |
470 (/ (+ (nth 2 a) ldiff) 2))))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
471 (math-sqrt-float-iter a guess))) |
40785 | 472 |
473 (defun math-sqrt-float-iter (a guess) ; [F F F] | |
474 (math-working "sqrt" guess) | |
475 (let ((g2 (math-mul-float (math-add-float guess (math-div-float a guess)) | |
476 '(float 5 -1)))) | |
477 (if (math-nearly-equal-float g2 guess) | |
478 g2 | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
479 (math-sqrt-float-iter a g2)))) |
40785 | 480 |
481 ;;; True if A and B differ only in the last digit of precision. [P F F] | |
482 (defun math-nearly-equal-float (a b) | |
483 (let ((ediff (- (nth 2 a) (nth 2 b)))) | |
484 (cond ((= ediff 0) ;; Expanded out for speed | |
485 (setq ediff (math-add (Math-integer-neg (nth 1 a)) (nth 1 b))) | |
486 (or (eq ediff 0) | |
487 (and (not (consp ediff)) | |
488 (< ediff 10) | |
489 (> ediff -10) | |
490 (= (math-numdigs (nth 1 a)) calc-internal-prec)))) | |
491 ((= ediff 1) | |
492 (setq ediff (math-add (Math-integer-neg (nth 1 b)) | |
493 (math-scale-int (nth 1 a) 1))) | |
494 (and (not (consp ediff)) | |
495 (< ediff 10) | |
496 (> ediff -10) | |
497 (= (math-numdigs (nth 1 b)) calc-internal-prec))) | |
498 ((= ediff -1) | |
499 (setq ediff (math-add (Math-integer-neg (nth 1 a)) | |
500 (math-scale-int (nth 1 b) 1))) | |
501 (and (not (consp ediff)) | |
502 (< ediff 10) | |
503 (> ediff -10) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
504 (= (math-numdigs (nth 1 a)) calc-internal-prec)))))) |
40785 | 505 |
506 (defun math-nearly-equal (a b) ; [P N N] [Public] | |
507 (setq a (math-float a)) | |
508 (setq b (math-float b)) | |
509 (if (eq (car a) 'polar) (setq a (math-complex a))) | |
510 (if (eq (car b) 'polar) (setq b (math-complex b))) | |
511 (if (eq (car a) 'cplx) | |
512 (if (eq (car b) 'cplx) | |
513 (and (or (math-nearly-equal-float (nth 1 a) (nth 1 b)) | |
514 (and (math-nearly-zerop-float (nth 1 a) (nth 2 a)) | |
515 (math-nearly-zerop-float (nth 1 b) (nth 2 b)))) | |
516 (or (math-nearly-equal-float (nth 2 a) (nth 2 b)) | |
517 (and (math-nearly-zerop-float (nth 2 a) (nth 1 a)) | |
518 (math-nearly-zerop-float (nth 2 b) (nth 1 b))))) | |
519 (and (math-nearly-equal-float (nth 1 a) b) | |
520 (math-nearly-zerop-float (nth 2 a) b))) | |
521 (if (eq (car b) 'cplx) | |
522 (and (math-nearly-equal-float a (nth 1 b)) | |
523 (math-nearly-zerop-float a (nth 2 b))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
524 (math-nearly-equal-float a b)))) |
40785 | 525 |
526 ;;; True if A is nearly zero compared to B. [P F F] | |
527 (defun math-nearly-zerop-float (a b) | |
528 (or (eq (nth 1 a) 0) | |
529 (<= (+ (math-numdigs (nth 1 a)) (nth 2 a)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
530 (1+ (- (+ (math-numdigs (nth 1 b)) (nth 2 b)) calc-internal-prec))))) |
40785 | 531 |
532 (defun math-nearly-zerop (a b) ; [P N R] [Public] | |
533 (setq a (math-float a)) | |
534 (setq b (math-float b)) | |
535 (if (eq (car a) 'cplx) | |
536 (and (math-nearly-zerop-float (nth 1 a) b) | |
537 (math-nearly-zerop-float (nth 2 a) b)) | |
538 (if (eq (car a) 'polar) | |
539 (math-nearly-zerop-float (nth 1 a) b) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
540 (math-nearly-zerop-float a b)))) |
40785 | 541 |
542 ;;; This implementation could be improved, accuracy-wise. | |
543 (defun math-hypot (a b) | |
544 (cond ((Math-zerop a) (math-abs b)) | |
545 ((Math-zerop b) (math-abs a)) | |
546 ((not (Math-scalarp a)) | |
547 (if (math-infinitep a) | |
548 (if (math-infinitep b) | |
549 (if (equal a b) | |
550 a | |
551 '(var nan var-nan)) | |
552 a) | |
553 (calc-record-why 'scalarp a) | |
554 (list 'calcFunc-hypot a b))) | |
555 ((not (Math-scalarp b)) | |
556 (if (math-infinitep b) | |
557 b | |
558 (calc-record-why 'scalarp b) | |
559 (list 'calcFunc-hypot a b))) | |
560 ((and (Math-numberp a) (Math-numberp b)) | |
561 (math-with-extra-prec 1 | |
562 (math-sqrt (math-add (calcFunc-abssqr a) (calcFunc-abssqr b))))) | |
563 ((eq (car-safe a) 'hms) | |
564 (if (eq (car-safe b) 'hms) ; this helps sdev's of hms forms | |
565 (math-to-hms (math-hypot (math-from-hms a 'deg) | |
566 (math-from-hms b 'deg))) | |
567 (math-to-hms (math-hypot (math-from-hms a 'deg) b)))) | |
568 ((eq (car-safe b) 'hms) | |
569 (math-to-hms (math-hypot a (math-from-hms b 'deg)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
570 (t nil))) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
571 (defalias 'calcFunc-hypot 'math-hypot) |
40785 | 572 |
573 (defun calcFunc-sqr (x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
574 (math-pow x 2)) |
40785 | 575 |
576 | |
577 | |
578 (defun math-nth-root (a n) | |
579 (cond ((= n 2) (math-sqrt a)) | |
580 ((Math-zerop a) a) | |
581 ((Math-negp a) nil) | |
582 ((Math-integerp a) | |
583 (let ((root (math-nth-root-integer a n))) | |
584 (if (car root) | |
585 (cdr root) | |
586 (and (not calc-symbolic-mode) | |
587 (math-nth-root-float (math-float a) n | |
588 (math-float (cdr root))))))) | |
589 ((eq (car-safe a) 'frac) | |
590 (let* ((num-root (math-nth-root-integer (nth 1 a) n)) | |
591 (den-root (math-nth-root-integer (nth 2 a) n))) | |
592 (if (and (car num-root) (car den-root)) | |
593 (list 'frac (cdr num-root) (cdr den-root)) | |
594 (and (not calc-symbolic-mode) | |
595 (math-nth-root-float | |
596 (math-float a) n | |
597 (math-div-float (math-float (cdr num-root)) | |
598 (math-float (cdr den-root)))))))) | |
599 ((eq (car-safe a) 'float) | |
600 (and (not calc-symbolic-mode) | |
601 (math-nth-root-float a n))) | |
602 ((eq (car-safe a) 'polar) | |
603 (let ((root (math-nth-root (nth 1 a) n))) | |
604 (and root (list 'polar root (math-div (nth 2 a) n))))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
605 (t nil))) |
40785 | 606 |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
607 ;; The variables math-nrf-n, math-nrf-nf and math-nrf-nfm1 are local |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
608 ;; to math-nth-root-float, but are used by math-nth-root-float-iter, |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
609 ;; which is called by math-nth-root-float. |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
610 (defvar math-nrf-n) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
611 (defvar math-nrf-nf) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
612 (defvar math-nrf-nfm1) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
613 |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
614 (defun math-nth-root-float (a math-nrf-n &optional guess) |
40785 | 615 (math-inexact-result) |
616 (math-with-extra-prec 1 | |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
617 (let ((math-nrf-nf (math-float math-nrf-n)) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
618 (math-nrf-nfm1 (math-float (1- math-nrf-n)))) |
40785 | 619 (math-nth-root-float-iter a (or guess |
620 (math-make-float | |
621 1 (/ (+ (math-numdigs (nth 1 a)) | |
622 (nth 2 a) | |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
623 (/ math-nrf-n 2)) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
624 math-nrf-n))))))) |
40785 | 625 |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
626 (defun math-nth-root-float-iter (a guess) |
40785 | 627 (math-working "root" guess) |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
628 (let ((g2 (math-div-float (math-add-float (math-mul math-nrf-nfm1 guess) |
40785 | 629 (math-div-float |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
630 a (math-ipow guess (1- math-nrf-n)))) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
631 math-nrf-nf))) |
40785 | 632 (if (math-nearly-equal-float g2 guess) |
633 g2 | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
634 (math-nth-root-float-iter a g2)))) |
40785 | 635 |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
636 ;; The variable math-nri-n is local to math-nth-root-integer, but |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
637 ;; is used by math-nth-root-int-iter, which is called by |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
638 ;; math-nth-root-int. |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
639 (defvar math-nri-n) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
640 |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
641 (defun math-nth-root-integer (a math-nri-n &optional guess) ; [I I S] |
40785 | 642 (math-nth-root-int-iter a (or guess |
643 (math-scale-int 1 (/ (+ (math-numdigs a) | |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
644 (1- math-nri-n)) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
645 math-nri-n))))) |
40785 | 646 |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
647 (defun math-nth-root-int-iter (a guess) |
40785 | 648 (math-working "root" guess) |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
649 (let* ((q (math-idivmod a (math-ipow guess (1- math-nri-n)))) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
650 (s (math-add (car q) (math-mul (1- math-nri-n) guess))) |
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
651 (g2 (math-idivmod s math-nri-n))) |
40785 | 652 (if (Math-natnum-lessp (car g2) guess) |
653 (math-nth-root-int-iter a (car g2)) | |
654 (cons (and (equal (car g2) guess) | |
655 (eq (cdr q) 0) | |
656 (eq (cdr g2) 0)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
657 guess)))) |
40785 | 658 |
659 (defun calcFunc-nroot (x n) | |
660 (calcFunc-pow x (if (integerp n) | |
661 (math-make-frac 1 n) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
662 (math-div 1 n)))) |
40785 | 663 |
664 | |
665 | |
666 | |
667 ;;;; Transcendental functions. | |
668 | |
669 ;;; All of these functions are defined on the complex plane. | |
670 ;;; (Branch cuts, etc. follow Steele's Common Lisp book.) | |
671 | |
672 ;;; Most functions increase calc-internal-prec by 2 digits, then round | |
673 ;;; down afterward. "-raw" functions use the current precision, require | |
674 ;;; their arguments to be in float (or complex float) format, and always | |
675 ;;; work in radians (where applicable). | |
676 | |
677 (defun math-to-radians (a) ; [N N] | |
678 (cond ((eq (car-safe a) 'hms) | |
679 (math-from-hms a 'rad)) | |
680 ((memq calc-angle-mode '(deg hms)) | |
681 (math-mul a (math-pi-over-180))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
682 (t a))) |
40785 | 683 |
684 (defun math-from-radians (a) ; [N N] | |
685 (cond ((eq calc-angle-mode 'deg) | |
686 (if (math-constp a) | |
687 (math-div a (math-pi-over-180)) | |
688 (list 'calcFunc-deg a))) | |
689 ((eq calc-angle-mode 'hms) | |
690 (math-to-hms a 'rad)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
691 (t a))) |
40785 | 692 |
693 (defun math-to-radians-2 (a) ; [N N] | |
694 (cond ((eq (car-safe a) 'hms) | |
695 (math-from-hms a 'rad)) | |
696 ((memq calc-angle-mode '(deg hms)) | |
697 (if calc-symbolic-mode | |
698 (math-div (math-mul a '(var pi var-pi)) 180) | |
699 (math-mul a (math-pi-over-180)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
700 (t a))) |
40785 | 701 |
702 (defun math-from-radians-2 (a) ; [N N] | |
703 (cond ((memq calc-angle-mode '(deg hms)) | |
704 (if calc-symbolic-mode | |
705 (math-div (math-mul 180 a) '(var pi var-pi)) | |
706 (math-div a (math-pi-over-180)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
707 (t a))) |
40785 | 708 |
709 | |
710 | |
711 ;;; Sine, cosine, and tangent. | |
712 | |
713 (defun calcFunc-sin (x) ; [N N] [Public] | |
714 (cond ((and (integerp x) | |
715 (if (eq calc-angle-mode 'deg) | |
716 (= (% x 90) 0) | |
717 (= x 0))) | |
718 (aref [0 1 0 -1] (math-mod (/ x 90) 4))) | |
719 ((Math-scalarp x) | |
720 (math-with-extra-prec 2 | |
721 (math-sin-raw (math-to-radians (math-float x))))) | |
722 ((eq (car x) 'sdev) | |
723 (if (math-constp x) | |
724 (math-with-extra-prec 2 | |
725 (let* ((xx (math-to-radians (math-float (nth 1 x)))) | |
726 (xs (math-to-radians (math-float (nth 2 x)))) | |
727 (sc (math-sin-cos-raw xx))) | |
728 (math-make-sdev (car sc) (math-mul xs (cdr sc))))) | |
729 (math-make-sdev (calcFunc-sin (nth 1 x)) | |
730 (math-mul (nth 2 x) (calcFunc-cos (nth 1 x)))))) | |
731 ((and (eq (car x) 'intv) (math-intv-constp x)) | |
732 (calcFunc-cos (math-sub x (math-quarter-circle nil)))) | |
733 ((equal x '(var nan var-nan)) | |
734 x) | |
735 (t (calc-record-why 'scalarp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
736 (list 'calcFunc-sin x)))) |
40785 | 737 |
738 (defun calcFunc-cos (x) ; [N N] [Public] | |
739 (cond ((and (integerp x) | |
740 (if (eq calc-angle-mode 'deg) | |
741 (= (% x 90) 0) | |
742 (= x 0))) | |
743 (aref [1 0 -1 0] (math-mod (/ x 90) 4))) | |
744 ((Math-scalarp x) | |
745 (math-with-extra-prec 2 | |
746 (math-cos-raw (math-to-radians (math-float x))))) | |
747 ((eq (car x) 'sdev) | |
748 (if (math-constp x) | |
749 (math-with-extra-prec 2 | |
750 (let* ((xx (math-to-radians (math-float (nth 1 x)))) | |
751 (xs (math-to-radians (math-float (nth 2 x)))) | |
752 (sc (math-sin-cos-raw xx))) | |
753 (math-make-sdev (cdr sc) (math-mul xs (car sc))))) | |
754 (math-make-sdev (calcFunc-cos (nth 1 x)) | |
755 (math-mul (nth 2 x) (calcFunc-sin (nth 1 x)))))) | |
756 ((and (eq (car x) 'intv) (math-intv-constp x)) | |
757 (math-with-extra-prec 2 | |
758 (let* ((xx (math-to-radians (math-float x))) | |
759 (na (math-floor (math-div (nth 2 xx) (math-pi)))) | |
760 (nb (math-floor (math-div (nth 3 xx) (math-pi)))) | |
761 (span (math-sub nb na))) | |
762 (if (memq span '(0 1)) | |
763 (let ((int (math-sort-intv (nth 1 x) | |
764 (math-cos-raw (nth 2 xx)) | |
765 (math-cos-raw (nth 3 xx))))) | |
766 (if (eq span 1) | |
767 (if (math-evenp na) | |
768 (math-make-intv (logior (nth 1 x) 2) | |
769 -1 | |
770 (nth 3 int)) | |
771 (math-make-intv (logior (nth 1 x) 1) | |
772 (nth 2 int) | |
773 1)) | |
774 int)) | |
775 (list 'intv 3 -1 1))))) | |
776 ((equal x '(var nan var-nan)) | |
777 x) | |
778 (t (calc-record-why 'scalarp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
779 (list 'calcFunc-cos x)))) |
40785 | 780 |
781 (defun calcFunc-sincos (x) ; [V N] [Public] | |
782 (if (Math-scalarp x) | |
783 (math-with-extra-prec 2 | |
784 (let ((sc (math-sin-cos-raw (math-to-radians (math-float x))))) | |
785 (list 'vec (cdr sc) (car sc)))) ; the vector [cos, sin] | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
786 (list 'vec (calcFunc-sin x) (calcFunc-cos x)))) |
40785 | 787 |
788 (defun calcFunc-tan (x) ; [N N] [Public] | |
789 (cond ((and (integerp x) | |
790 (if (eq calc-angle-mode 'deg) | |
791 (= (% x 180) 0) | |
792 (= x 0))) | |
793 0) | |
794 ((Math-scalarp x) | |
795 (math-with-extra-prec 2 | |
796 (math-tan-raw (math-to-radians (math-float x))))) | |
797 ((eq (car x) 'sdev) | |
798 (if (math-constp x) | |
799 (math-with-extra-prec 2 | |
800 (let* ((xx (math-to-radians (math-float (nth 1 x)))) | |
801 (xs (math-to-radians (math-float (nth 2 x)))) | |
802 (sc (math-sin-cos-raw xx))) | |
803 (if (and (math-zerop (cdr sc)) (not calc-infinite-mode)) | |
804 (progn | |
805 (calc-record-why "*Division by zero") | |
806 (list 'calcFunc-tan x)) | |
807 (math-make-sdev (math-div-float (car sc) (cdr sc)) | |
808 (math-div-float xs (math-sqr (cdr sc))))))) | |
809 (math-make-sdev (calcFunc-tan (nth 1 x)) | |
810 (math-div (nth 2 x) | |
811 (math-sqr (calcFunc-cos (nth 1 x))))))) | |
812 ((and (eq (car x) 'intv) (math-intv-constp x)) | |
813 (or (math-with-extra-prec 2 | |
814 (let* ((xx (math-to-radians (math-float x))) | |
815 (na (math-floor (math-div (math-sub (nth 2 xx) | |
816 (math-pi-over-2)) | |
817 (math-pi)))) | |
818 (nb (math-floor (math-div (math-sub (nth 3 xx) | |
819 (math-pi-over-2)) | |
820 (math-pi))))) | |
821 (and (equal na nb) | |
822 (math-sort-intv (nth 1 x) | |
823 (math-tan-raw (nth 2 xx)) | |
824 (math-tan-raw (nth 3 xx)))))) | |
825 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)))) | |
826 ((equal x '(var nan var-nan)) | |
827 x) | |
828 (t (calc-record-why 'scalarp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
829 (list 'calcFunc-tan x)))) |
40785 | 830 |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
831 (defun calcFunc-sec (x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
832 (cond ((and (integerp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
833 (eq calc-angle-mode 'deg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
834 (= (% x 180) 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
835 (if (= (% x 360) 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
836 1 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
837 -1)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
838 ((and (integerp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
839 (eq calc-angle-mode 'rad) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
840 (= x 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
841 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
842 ((Math-scalarp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
843 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
844 (math-sec-raw (math-to-radians (math-float x))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
845 ((eq (car x) 'sdev) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
846 (if (math-constp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
847 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
848 (let* ((xx (math-to-radians (math-float (nth 1 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
849 (xs (math-to-radians (math-float (nth 2 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
850 (sc (math-sin-cos-raw xx))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
851 (if (and (math-zerop (cdr sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
852 (not calc-infinite-mode)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
853 (progn |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
854 (calc-record-why "*Division by zero") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
855 (list 'calcFunc-sec x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
856 (math-make-sdev (math-div-float '(float 1 0) (cdr sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
857 (math-div-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
858 (math-mul xs (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
859 (math-sqr (cdr sc))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
860 (math-make-sdev (calcFunc-sec (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
861 (math-div |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
862 (math-mul (nth 2 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
863 (calcFunc-sin (nth 1 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
864 (math-sqr (calcFunc-cos (nth 1 x))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
865 ((and (eq (car x) 'intv) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
866 (math-intv-constp x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
867 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
868 (let* ((xx (math-to-radians (math-float x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
869 (na (math-floor (math-div (math-sub (nth 2 xx) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
870 (math-pi-over-2)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
871 (math-pi)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
872 (nb (math-floor (math-div (math-sub (nth 3 xx) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
873 (math-pi-over-2)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
874 (math-pi)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
875 (naa (math-floor (math-div (nth 2 xx) (math-pi-over-2)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
876 (nbb (math-floor (math-div (nth 3 xx) (math-pi-over-2)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
877 (span (math-sub nbb naa))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
878 (if (not (equal na nb)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
879 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
880 (let ((int (math-sort-intv (nth 1 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
881 (math-sec-raw (nth 2 xx)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
882 (math-sec-raw (nth 3 xx))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
883 (if (eq span 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
884 (if (math-evenp (math-div (math-add naa 1) 2)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
885 (math-make-intv (logior (nth 1 int) 2) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
886 1 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
887 (nth 3 int)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
888 (math-make-intv (logior (nth 1 int) 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
889 (nth 2 int) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
890 -1)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
891 int)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
892 ((equal x '(var nan var-nan)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
893 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
894 (t (calc-record-why 'scalarp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
895 (list 'calcFunc-sec x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
896 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
897 (defun calcFunc-csc (x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
898 (cond ((and (integerp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
899 (eq calc-angle-mode 'deg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
900 (= (% (- x 90) 180) 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
901 (if (= (% (- x 90) 360) 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
902 1 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
903 -1)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
904 ((Math-scalarp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
905 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
906 (math-csc-raw (math-to-radians (math-float x))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
907 ((eq (car x) 'sdev) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
908 (if (math-constp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
909 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
910 (let* ((xx (math-to-radians (math-float (nth 1 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
911 (xs (math-to-radians (math-float (nth 2 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
912 (sc (math-sin-cos-raw xx))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
913 (if (and (math-zerop (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
914 (not calc-infinite-mode)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
915 (progn |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
916 (calc-record-why "*Division by zero") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
917 (list 'calcFunc-csc x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
918 (math-make-sdev (math-div-float '(float 1 0) (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
919 (math-div-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
920 (math-mul xs (cdr sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
921 (math-sqr (car sc))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
922 (math-make-sdev (calcFunc-csc (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
923 (math-div |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
924 (math-mul (nth 2 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
925 (calcFunc-cos (nth 1 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
926 (math-sqr (calcFunc-sin (nth 1 x))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
927 ((and (eq (car x) 'intv) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
928 (math-intv-constp x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
929 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
930 (let* ((xx (math-to-radians (math-float x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
931 (na (math-floor (math-div (nth 2 xx) (math-pi)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
932 (nb (math-floor (math-div (nth 3 xx) (math-pi)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
933 (naa (math-floor (math-div (nth 2 xx) (math-pi-over-2)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
934 (nbb (math-floor (math-div (nth 3 xx) (math-pi-over-2)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
935 (span (math-sub nbb naa))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
936 (if (not (equal na nb)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
937 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
938 (let ((int (math-sort-intv (nth 1 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
939 (math-csc-raw (nth 2 xx)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
940 (math-csc-raw (nth 3 xx))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
941 (if (eq span 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
942 (if (math-evenp (math-div naa 2)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
943 (math-make-intv (logior (nth 1 int) 2) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
944 1 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
945 (nth 3 int)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
946 (math-make-intv (logior (nth 1 int) 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
947 (nth 2 int) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
948 -1)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
949 int)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
950 ((equal x '(var nan var-nan)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
951 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
952 (t (calc-record-why 'scalarp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
953 (list 'calcFunc-csc x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
954 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
955 (defun calcFunc-cot (x) ; [N N] [Public] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
956 (cond ((and (integerp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
957 (if (eq calc-angle-mode 'deg) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
958 (= (% (- x 90) 180) 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
959 (= x 0))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
960 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
961 ((Math-scalarp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
962 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
963 (math-cot-raw (math-to-radians (math-float x))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
964 ((eq (car x) 'sdev) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
965 (if (math-constp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
966 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
967 (let* ((xx (math-to-radians (math-float (nth 1 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
968 (xs (math-to-radians (math-float (nth 2 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
969 (sc (math-sin-cos-raw xx))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
970 (if (and (math-zerop (car sc)) (not calc-infinite-mode)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
971 (progn |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
972 (calc-record-why "*Division by zero") |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
973 (list 'calcFunc-cot x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
974 (math-make-sdev (math-div-float (cdr sc) (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
975 (math-div-float xs (math-sqr (car sc))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
976 (math-make-sdev (calcFunc-cot (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
977 (math-div (nth 2 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
978 (math-sqr (calcFunc-sin (nth 1 x))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
979 ((and (eq (car x) 'intv) (math-intv-constp x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
980 (or (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
981 (let* ((xx (math-to-radians (math-float x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
982 (na (math-floor (math-div (nth 2 xx) (math-pi)))) |
60164
697e2ba683cc
(calc-arctan, calc-tanh, calc-arctanh): Removed extra definitions.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60085
diff
changeset
|
983 (nb (math-floor (math-div (nth 3 xx) (math-pi))))) |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
984 (and (equal na nb) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
985 (math-sort-intv (nth 1 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
986 (math-cot-raw (nth 2 xx)) |
60164
697e2ba683cc
(calc-arctan, calc-tanh, calc-arctanh): Removed extra definitions.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60085
diff
changeset
|
987 (math-cot-raw (nth 3 xx)))))) |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
988 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
989 ((equal x '(var nan var-nan)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
990 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
991 (t (calc-record-why 'scalarp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
992 (list 'calcFunc-cot x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
993 |
40785 | 994 (defun math-sin-raw (x) ; [N N] |
995 (cond ((eq (car x) 'cplx) | |
996 (let* ((expx (math-exp-raw (nth 2 x))) | |
997 (expmx (math-div-float '(float 1 0) expx)) | |
998 (sc (math-sin-cos-raw (nth 1 x)))) | |
999 (list 'cplx | |
1000 (math-mul-float (car sc) | |
1001 (math-mul-float (math-add-float expx expmx) | |
1002 '(float 5 -1))) | |
1003 (math-mul-float (cdr sc) | |
1004 (math-mul-float (math-sub-float expx expmx) | |
1005 '(float 5 -1)))))) | |
1006 ((eq (car x) 'polar) | |
1007 (math-polar (math-sin-raw (math-complex x)))) | |
1008 ((Math-integer-negp (nth 1 x)) | |
1009 (math-neg-float (math-sin-raw (math-neg-float x)))) | |
1010 ((math-lessp-float '(float 7 0) x) ; avoid inf loops due to roundoff | |
1011 (math-sin-raw (math-mod x (math-two-pi)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1012 (t (math-sin-raw-2 x x)))) |
40785 | 1013 |
1014 (defun math-cos-raw (x) ; [N N] | |
1015 (if (eq (car-safe x) 'polar) | |
1016 (math-polar (math-cos-raw (math-complex x))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1017 (math-sin-raw (math-sub (math-pi-over-2) x)))) |
40785 | 1018 |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1019 (defun math-sec-raw (x) ; [N N] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1020 (cond ((eq (car x) 'cplx) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1021 (let* ((x (math-mul x '(float 1 0))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1022 (expx (math-exp-raw (nth 2 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1023 (expmx (math-div-float '(float 1 0) expx)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1024 (sh (math-mul-float (math-sub-float expx expmx) '(float 5 -1))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1025 (ch (math-mul-float (math-add-float expx expmx) '(float 5 -1))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1026 (sc (math-sin-cos-raw (nth 1 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1027 (d (math-add-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1028 (math-mul-float (math-sqr (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1029 (math-sqr sh)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1030 (math-mul-float (math-sqr (cdr sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1031 (math-sqr ch))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1032 (and (not (eq (nth 1 d) 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1033 (list 'cplx |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1034 (math-div-float (math-mul-float (cdr sc) ch) d) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1035 (math-div-float (math-mul-float (car sc) sh) d))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1036 ((eq (car x) 'polar) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1037 (math-polar (math-sec-raw (math-complex x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1038 (t |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1039 (let ((cs (math-cos-raw x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1040 (if (eq cs 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1041 (math-div 1 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1042 (math-div-float '(float 1 0) cs)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1043 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1044 (defun math-csc-raw (x) ; [N N] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1045 (cond ((eq (car x) 'cplx) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1046 (let* ((x (math-mul x '(float 1 0))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1047 (expx (math-exp-raw (nth 2 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1048 (expmx (math-div-float '(float 1 0) expx)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1049 (sh (math-mul-float (math-sub-float expx expmx) '(float 5 -1))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1050 (ch (math-mul-float (math-add-float expx expmx) '(float 5 -1))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1051 (sc (math-sin-cos-raw (nth 1 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1052 (d (math-add-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1053 (math-mul-float (math-sqr (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1054 (math-sqr ch)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1055 (math-mul-float (math-sqr (cdr sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1056 (math-sqr sh))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1057 (and (not (eq (nth 1 d) 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1058 (list 'cplx |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1059 (math-div-float (math-mul-float (car sc) ch) d) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1060 (math-div-float (math-mul-float (cdr sc) sh) d))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1061 ((eq (car x) 'polar) |
60085
f91c9a606821
(math-csc-raw): Fix typo.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60079
diff
changeset
|
1062 (math-polar (math-csc-raw (math-complex x)))) |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1063 (t |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1064 (let ((sn (math-sin-raw x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1065 (if (eq sn 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1066 (math-div 1 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1067 (math-div-float '(float 1 0) sn)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1068 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1069 (defun math-cot-raw (x) ; [N N] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1070 (cond ((eq (car x) 'cplx) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1071 (let* ((x (math-mul x '(float 1 0))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1072 (expx (math-exp-raw (nth 2 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1073 (expmx (math-div-float '(float 1 0) expx)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1074 (sh (math-mul-float (math-sub-float expx expmx) '(float 5 -1))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1075 (ch (math-mul-float (math-add-float expx expmx) '(float 5 -1))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1076 (sc (math-sin-cos-raw (nth 1 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1077 (d (math-add-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1078 (math-sqr (car sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1079 (math-sqr sh)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1080 (and (not (eq (nth 1 d) 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1081 (list 'cplx |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1082 (math-div-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1083 (math-mul-float (car sc) (cdr sc)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1084 d) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1085 (math-neg |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1086 (math-div-float |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1087 (math-mul-float sh ch) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1088 d)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1089 ((eq (car x) 'polar) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1090 (math-polar (math-cot-raw (math-complex x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1091 (t |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1092 (let ((sc (math-sin-cos-raw x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1093 (if (eq (nth 1 (car sc)) 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1094 (math-div (cdr sc) 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1095 (math-div-float (cdr sc) (car sc))))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1096 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1097 |
40785 | 1098 ;;; This could use a smarter method: Reduce x as in math-sin-raw, then |
1099 ;;; compute either sin(x) or cos(x), whichever is smaller, and compute | |
1100 ;;; the other using the identity sin(x)^2 + cos(x)^2 = 1. | |
1101 (defun math-sin-cos-raw (x) ; [F.F F] (result is (sin x . cos x)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1102 (cons (math-sin-raw x) (math-cos-raw x))) |
40785 | 1103 |
1104 (defun math-tan-raw (x) ; [N N] | |
1105 (cond ((eq (car x) 'cplx) | |
1106 (let* ((x (math-mul x '(float 2 0))) | |
1107 (expx (math-exp-raw (nth 2 x))) | |
1108 (expmx (math-div-float '(float 1 0) expx)) | |
1109 (sc (math-sin-cos-raw (nth 1 x))) | |
1110 (d (math-add-float (cdr sc) | |
1111 (math-mul-float (math-add-float expx expmx) | |
1112 '(float 5 -1))))) | |
1113 (and (not (eq (nth 1 d) 0)) | |
1114 (list 'cplx | |
1115 (math-div-float (car sc) d) | |
1116 (math-div-float (math-mul-float (math-sub-float expx | |
1117 expmx) | |
1118 '(float 5 -1)) d))))) | |
1119 ((eq (car x) 'polar) | |
1120 (math-polar (math-tan-raw (math-complex x)))) | |
1121 (t | |
1122 (let ((sc (math-sin-cos-raw x))) | |
1123 (if (eq (nth 1 (cdr sc)) 0) | |
1124 (math-div (car sc) 0) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1125 (math-div-float (car sc) (cdr sc))))))) |
40785 | 1126 |
1127 (defun math-sin-raw-2 (x orgx) ; This avoids poss of inf recursion. [F F] | |
1128 (let ((xmpo2 (math-sub-float (math-pi-over-2) x))) | |
1129 (cond ((Math-integer-negp (nth 1 xmpo2)) | |
1130 (math-neg-float (math-sin-raw-2 (math-sub-float x (math-pi)) | |
1131 orgx))) | |
1132 ((math-lessp-float (math-pi-over-4) x) | |
1133 (math-cos-raw-2 xmpo2 orgx)) | |
1134 ((math-lessp-float x (math-neg (math-pi-over-4))) | |
1135 (math-neg (math-cos-raw-2 (math-add (math-pi-over-2) x) orgx))) | |
1136 ((math-nearly-zerop-float x orgx) '(float 0 0)) | |
1137 (calc-symbolic-mode (signal 'inexact-result nil)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1138 (t (math-sin-series x 6 4 x (math-neg-float (math-sqr-float x))))))) |
40785 | 1139 |
1140 (defun math-cos-raw-2 (x orgx) ; [F F] | |
1141 (cond ((math-nearly-zerop-float x orgx) '(float 1 0)) | |
1142 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1143 (t (let ((xnegsqr (math-neg-float (math-sqr-float x)))) | |
1144 (math-sin-series | |
1145 (math-add-float '(float 1 0) | |
1146 (math-mul-float xnegsqr '(float 5 -1))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1147 24 5 xnegsqr xnegsqr))))) |
40785 | 1148 |
1149 (defun math-sin-series (sum nfac n x xnegsqr) | |
1150 (math-working "sin" sum) | |
1151 (let* ((nextx (math-mul-float x xnegsqr)) | |
1152 (nextsum (math-add-float sum (math-div-float nextx | |
1153 (math-float nfac))))) | |
1154 (if (math-nearly-equal-float sum nextsum) | |
1155 sum | |
1156 (math-sin-series nextsum (math-mul nfac (* n (1+ n))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1157 (+ n 2) nextx xnegsqr)))) |
40785 | 1158 |
1159 | |
1160 ;;; Inverse sine, cosine, tangent. | |
1161 | |
1162 (defun calcFunc-arcsin (x) ; [N N] [Public] | |
1163 (cond ((eq x 0) 0) | |
1164 ((and (eq x 1) (eq calc-angle-mode 'deg)) 90) | |
1165 ((and (eq x -1) (eq calc-angle-mode 'deg)) -90) | |
1166 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1167 ((Math-numberp x) | |
1168 (math-with-extra-prec 2 | |
1169 (math-from-radians (math-arcsin-raw (math-float x))))) | |
1170 ((eq (car x) 'sdev) | |
1171 (math-make-sdev (calcFunc-arcsin (nth 1 x)) | |
1172 (math-from-radians | |
1173 (math-div (nth 2 x) | |
1174 (math-sqrt | |
1175 (math-sub 1 (math-sqr (nth 1 x)))))))) | |
1176 ((eq (car x) 'intv) | |
1177 (math-sort-intv (nth 1 x) | |
1178 (calcFunc-arcsin (nth 2 x)) | |
1179 (calcFunc-arcsin (nth 3 x)))) | |
1180 ((equal x '(var nan var-nan)) | |
1181 x) | |
1182 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1183 (list 'calcFunc-arcsin x)))) |
40785 | 1184 |
1185 (defun calcFunc-arccos (x) ; [N N] [Public] | |
1186 (cond ((eq x 1) 0) | |
1187 ((and (eq x 0) (eq calc-angle-mode 'deg)) 90) | |
1188 ((and (eq x -1) (eq calc-angle-mode 'deg)) 180) | |
1189 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1190 ((Math-numberp x) | |
1191 (math-with-extra-prec 2 | |
1192 (math-from-radians (math-arccos-raw (math-float x))))) | |
1193 ((eq (car x) 'sdev) | |
1194 (math-make-sdev (calcFunc-arccos (nth 1 x)) | |
1195 (math-from-radians | |
1196 (math-div (nth 2 x) | |
1197 (math-sqrt | |
1198 (math-sub 1 (math-sqr (nth 1 x)))))))) | |
1199 ((eq (car x) 'intv) | |
1200 (math-sort-intv (nth 1 x) | |
1201 (calcFunc-arccos (nth 2 x)) | |
1202 (calcFunc-arccos (nth 3 x)))) | |
1203 ((equal x '(var nan var-nan)) | |
1204 x) | |
1205 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1206 (list 'calcFunc-arccos x)))) |
40785 | 1207 |
1208 (defun calcFunc-arctan (x) ; [N N] [Public] | |
1209 (cond ((eq x 0) 0) | |
1210 ((and (eq x 1) (eq calc-angle-mode 'deg)) 45) | |
1211 ((and (eq x -1) (eq calc-angle-mode 'deg)) -45) | |
1212 ((Math-numberp x) | |
1213 (math-with-extra-prec 2 | |
1214 (math-from-radians (math-arctan-raw (math-float x))))) | |
1215 ((eq (car x) 'sdev) | |
1216 (math-make-sdev (calcFunc-arctan (nth 1 x)) | |
1217 (math-from-radians | |
1218 (math-div (nth 2 x) | |
1219 (math-add 1 (math-sqr (nth 1 x))))))) | |
1220 ((eq (car x) 'intv) | |
1221 (math-sort-intv (nth 1 x) | |
1222 (calcFunc-arctan (nth 2 x)) | |
1223 (calcFunc-arctan (nth 3 x)))) | |
1224 ((equal x '(var inf var-inf)) | |
1225 (math-quarter-circle t)) | |
1226 ((equal x '(neg (var inf var-inf))) | |
1227 (math-neg (math-quarter-circle t))) | |
1228 ((equal x '(var nan var-nan)) | |
1229 x) | |
1230 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1231 (list 'calcFunc-arctan x)))) |
40785 | 1232 |
1233 (defun math-arcsin-raw (x) ; [N N] | |
1234 (let ((a (math-sqrt-raw (math-sub '(float 1 0) (math-sqr x))))) | |
1235 (if (or (memq (car x) '(cplx polar)) | |
1236 (memq (car a) '(cplx polar))) | |
1237 (math-with-extra-prec 2 ; use extra precision for difficult case | |
1238 (math-mul '(cplx 0 -1) | |
1239 (math-ln-raw (math-add (math-mul '(cplx 0 1) x) a)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1240 (math-arctan2-raw x a)))) |
40785 | 1241 |
1242 (defun math-arccos-raw (x) ; [N N] | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1243 (math-sub (math-pi-over-2) (math-arcsin-raw x))) |
40785 | 1244 |
1245 (defun math-arctan-raw (x) ; [N N] | |
1246 (cond ((memq (car x) '(cplx polar)) | |
1247 (math-with-extra-prec 2 ; extra-extra | |
1248 (math-div (math-sub | |
1249 (math-ln-raw (math-add 1 (math-mul '(cplx 0 1) x))) | |
1250 (math-ln-raw (math-add 1 (math-mul '(cplx 0 -1) x)))) | |
1251 '(cplx 0 2)))) | |
1252 ((Math-integer-negp (nth 1 x)) | |
1253 (math-neg-float (math-arctan-raw (math-neg-float x)))) | |
1254 ((math-zerop x) x) | |
1255 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1256 ((math-equal-int x 1) (math-pi-over-4)) | |
1257 ((math-equal-int x -1) (math-neg (math-pi-over-4))) | |
1258 ((math-lessp-float '(float 414214 -6) x) ; if x > sqrt(2) - 1, reduce | |
1259 (if (math-lessp-float '(float 1 0) x) | |
1260 (math-sub-float (math-mul-float (math-pi) '(float 5 -1)) | |
1261 (math-arctan-raw (math-div-float '(float 1 0) x))) | |
1262 (math-sub-float (math-mul-float (math-pi) '(float 25 -2)) | |
1263 (math-arctan-raw (math-div-float | |
1264 (math-sub-float '(float 1 0) x) | |
1265 (math-add-float '(float 1 0) | |
1266 x)))))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1267 (t (math-arctan-series x 3 x (math-neg-float (math-sqr-float x)))))) |
40785 | 1268 |
1269 (defun math-arctan-series (sum n x xnegsqr) | |
1270 (math-working "arctan" sum) | |
1271 (let* ((nextx (math-mul-float x xnegsqr)) | |
1272 (nextsum (math-add-float sum (math-div-float nextx (math-float n))))) | |
1273 (if (math-nearly-equal-float sum nextsum) | |
1274 sum | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1275 (math-arctan-series nextsum (+ n 2) nextx xnegsqr)))) |
40785 | 1276 |
1277 (defun calcFunc-arctan2 (y x) ; [F R R] [Public] | |
1278 (if (Math-anglep y) | |
1279 (if (Math-anglep x) | |
1280 (math-with-extra-prec 2 | |
1281 (math-from-radians (math-arctan2-raw (math-float y) | |
1282 (math-float x)))) | |
1283 (calc-record-why 'anglep x) | |
1284 (list 'calcFunc-arctan2 y x)) | |
1285 (if (and (or (math-infinitep x) (math-anglep x)) | |
1286 (or (math-infinitep y) (math-anglep y))) | |
1287 (progn | |
1288 (if (math-posp x) | |
1289 (setq x 1) | |
1290 (if (math-negp x) | |
1291 (setq x -1) | |
1292 (or (math-zerop x) | |
1293 (setq x nil)))) | |
1294 (if (math-posp y) | |
1295 (setq y 1) | |
1296 (if (math-negp y) | |
1297 (setq y -1) | |
1298 (or (math-zerop y) | |
1299 (setq y nil)))) | |
1300 (if (and y x) | |
1301 (calcFunc-arctan2 y x) | |
1302 '(var nan var-nan))) | |
1303 (calc-record-why 'anglep y) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1304 (list 'calcFunc-arctan2 y x)))) |
40785 | 1305 |
1306 (defun math-arctan2-raw (y x) ; [F R R] | |
1307 (cond ((math-zerop y) | |
1308 (if (math-negp x) (math-pi) | |
1309 (if (or (math-floatp x) (math-floatp y)) '(float 0 0) 0))) | |
1310 ((math-zerop x) | |
1311 (if (math-posp y) | |
1312 (math-pi-over-2) | |
1313 (math-neg (math-pi-over-2)))) | |
1314 ((math-posp x) | |
1315 (math-arctan-raw (math-div-float y x))) | |
1316 ((math-posp y) | |
1317 (math-add-float (math-arctan-raw (math-div-float y x)) | |
1318 (math-pi))) | |
1319 (t | |
1320 (math-sub-float (math-arctan-raw (math-div-float y x)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1321 (math-pi))))) |
40785 | 1322 |
1323 (defun calcFunc-arcsincos (x) ; [V N] [Public] | |
1324 (if (and (Math-vectorp x) | |
1325 (= (length x) 3)) | |
1326 (calcFunc-arctan2 (nth 2 x) (nth 1 x)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1327 (math-reject-arg x "*Two-element vector expected"))) |
40785 | 1328 |
1329 | |
1330 | |
1331 ;;; Exponential function. | |
1332 | |
1333 (defun calcFunc-exp (x) ; [N N] [Public] | |
1334 (cond ((eq x 0) 1) | |
1335 ((and (memq x '(1 -1)) calc-symbolic-mode) | |
1336 (if (eq x 1) '(var e var-e) (math-div 1 '(var e var-e)))) | |
1337 ((Math-numberp x) | |
1338 (math-with-extra-prec 2 (math-exp-raw (math-float x)))) | |
1339 ((eq (car-safe x) 'sdev) | |
1340 (let ((ex (calcFunc-exp (nth 1 x)))) | |
1341 (math-make-sdev ex (math-mul (nth 2 x) ex)))) | |
1342 ((eq (car-safe x) 'intv) | |
1343 (math-make-intv (nth 1 x) (calcFunc-exp (nth 2 x)) | |
1344 (calcFunc-exp (nth 3 x)))) | |
1345 ((equal x '(var inf var-inf)) | |
1346 x) | |
1347 ((equal x '(neg (var inf var-inf))) | |
1348 0) | |
1349 ((equal x '(var nan var-nan)) | |
1350 x) | |
1351 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1352 (list 'calcFunc-exp x)))) |
40785 | 1353 |
1354 (defun calcFunc-expm1 (x) ; [N N] [Public] | |
1355 (cond ((eq x 0) 0) | |
1356 ((math-zerop x) '(float 0 0)) | |
1357 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1358 ((Math-numberp x) | |
1359 (math-with-extra-prec 2 | |
1360 (let ((x (math-float x))) | |
1361 (if (and (eq (car x) 'float) | |
1362 (math-lessp-float x '(float 1 0)) | |
1363 (math-lessp-float '(float -1 0) x)) | |
1364 (math-exp-minus-1-raw x) | |
1365 (math-add (math-exp-raw x) -1))))) | |
1366 ((eq (car-safe x) 'sdev) | |
1367 (if (math-constp x) | |
1368 (let ((ex (calcFunc-expm1 (nth 1 x)))) | |
1369 (math-make-sdev ex (math-mul (nth 2 x) (math-add ex 1)))) | |
1370 (math-make-sdev (calcFunc-expm1 (nth 1 x)) | |
1371 (math-mul (nth 2 x) (calcFunc-exp (nth 1 x)))))) | |
1372 ((eq (car-safe x) 'intv) | |
1373 (math-make-intv (nth 1 x) | |
1374 (calcFunc-expm1 (nth 2 x)) | |
1375 (calcFunc-expm1 (nth 3 x)))) | |
1376 ((equal x '(var inf var-inf)) | |
1377 x) | |
1378 ((equal x '(neg (var inf var-inf))) | |
1379 -1) | |
1380 ((equal x '(var nan var-nan)) | |
1381 x) | |
1382 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1383 (list 'calcFunc-expm1 x)))) |
40785 | 1384 |
1385 (defun calcFunc-exp10 (x) ; [N N] [Public] | |
1386 (if (eq x 0) | |
1387 1 | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1388 (math-pow '(float 1 1) x))) |
40785 | 1389 |
1390 (defun math-exp-raw (x) ; [N N] | |
1391 (cond ((math-zerop x) '(float 1 0)) | |
1392 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1393 ((eq (car x) 'cplx) | |
1394 (let ((expx (math-exp-raw (nth 1 x))) | |
1395 (sc (math-sin-cos-raw (nth 2 x)))) | |
1396 (list 'cplx | |
1397 (math-mul-float expx (cdr sc)) | |
1398 (math-mul-float expx (car sc))))) | |
1399 ((eq (car x) 'polar) | |
1400 (let ((xc (math-complex x))) | |
1401 (list 'polar | |
1402 (math-exp-raw (nth 1 xc)) | |
1403 (math-from-radians (nth 2 xc))))) | |
1404 ((or (math-lessp-float '(float 5 -1) x) | |
1405 (math-lessp-float x '(float -5 -1))) | |
1406 (if (math-lessp-float '(float 921035 1) x) | |
1407 (math-overflow) | |
1408 (if (math-lessp-float x '(float -921035 1)) | |
1409 (math-underflow))) | |
1410 (let* ((two-x (math-mul-float x '(float 2 0))) | |
1411 (hint (math-scale-int (nth 1 two-x) (nth 2 two-x))) | |
1412 (hfrac (math-sub-float x (math-mul-float (math-float hint) | |
1413 '(float 5 -1))))) | |
1414 (math-mul-float (math-ipow (math-sqrt-e) hint) | |
1415 (math-add-float '(float 1 0) | |
1416 (math-exp-minus-1-raw hfrac))))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1417 (t (math-add-float '(float 1 0) (math-exp-minus-1-raw x))))) |
40785 | 1418 |
1419 (defun math-exp-minus-1-raw (x) ; [F F] | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1420 (math-exp-series x 2 3 x x)) |
40785 | 1421 |
1422 (defun math-exp-series (sum nfac n xpow x) | |
1423 (math-working "exp" sum) | |
1424 (let* ((nextx (math-mul-float xpow x)) | |
1425 (nextsum (math-add-float sum (math-div-float nextx | |
1426 (math-float nfac))))) | |
1427 (if (math-nearly-equal-float sum nextsum) | |
1428 sum | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1429 (math-exp-series nextsum (math-mul nfac n) (1+ n) nextx x)))) |
40785 | 1430 |
1431 | |
1432 | |
1433 ;;; Logarithms. | |
1434 | |
1435 (defun calcFunc-ln (x) ; [N N] [Public] | |
1436 (cond ((math-zerop x) | |
1437 (if calc-infinite-mode | |
1438 '(neg (var inf var-inf)) | |
1439 (math-reject-arg x "*Logarithm of zero"))) | |
1440 ((eq x 1) 0) | |
1441 ((Math-numberp x) | |
1442 (math-with-extra-prec 2 (math-ln-raw (math-float x)))) | |
1443 ((eq (car-safe x) 'sdev) | |
1444 (math-make-sdev (calcFunc-ln (nth 1 x)) | |
1445 (math-div (nth 2 x) (nth 1 x)))) | |
1446 ((and (eq (car-safe x) 'intv) (or (Math-posp (nth 2 x)) | |
1447 (Math-zerop (nth 2 x)) | |
1448 (not (math-intv-constp x)))) | |
1449 (let ((calc-infinite-mode t)) | |
1450 (math-make-intv (nth 1 x) (calcFunc-ln (nth 2 x)) | |
1451 (calcFunc-ln (nth 3 x))))) | |
1452 ((equal x '(var e var-e)) | |
1453 1) | |
1454 ((and (eq (car-safe x) '^) | |
1455 (equal (nth 1 x) '(var e var-e)) | |
1456 (math-known-realp (nth 2 x))) | |
1457 (nth 2 x)) | |
1458 ((math-infinitep x) | |
1459 (if (equal x '(var nan var-nan)) | |
1460 x | |
1461 '(var inf var-inf))) | |
1462 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1463 (list 'calcFunc-ln x)))) |
40785 | 1464 |
1465 (defun calcFunc-log10 (x) ; [N N] [Public] | |
1466 (cond ((math-equal-int x 1) | |
1467 (if (math-floatp x) '(float 0 0) 0)) | |
1468 ((and (Math-integerp x) | |
1469 (math-posp x) | |
1470 (let ((res (math-integer-log x 10))) | |
1471 (and (car res) | |
1472 (setq x (cdr res))))) | |
1473 x) | |
1474 ((and (eq (car-safe x) 'frac) | |
1475 (eq (nth 1 x) 1) | |
1476 (let ((res (math-integer-log (nth 2 x) 10))) | |
1477 (and (car res) | |
1478 (setq x (- (cdr res)))))) | |
1479 x) | |
1480 ((math-zerop x) | |
1481 (if calc-infinite-mode | |
1482 '(neg (var inf var-inf)) | |
1483 (math-reject-arg x "*Logarithm of zero"))) | |
1484 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1485 ((Math-numberp x) | |
1486 (math-with-extra-prec 2 | |
1487 (let ((xf (math-float x))) | |
1488 (if (eq (nth 1 xf) 0) | |
1489 (math-reject-arg x "*Logarithm of zero")) | |
1490 (if (Math-integer-posp (nth 1 xf)) | |
1491 (if (eq (nth 1 xf) 1) ; log10(1*10^n) = n | |
1492 (math-float (nth 2 xf)) | |
1493 (let ((xdigs (1- (math-numdigs (nth 1 xf))))) | |
1494 (math-add-float | |
1495 (math-div-float (math-ln-raw-2 | |
1496 (list 'float (nth 1 xf) (- xdigs))) | |
1497 (math-ln-10)) | |
1498 (math-float (+ (nth 2 xf) xdigs))))) | |
1499 (math-div (calcFunc-ln xf) (math-ln-10)))))) | |
1500 ((eq (car-safe x) 'sdev) | |
1501 (math-make-sdev (calcFunc-log10 (nth 1 x)) | |
1502 (math-div (nth 2 x) | |
1503 (math-mul (nth 1 x) (math-ln-10))))) | |
1504 ((and (eq (car-safe x) 'intv) (or (Math-posp (nth 2 x)) | |
1505 (not (math-intv-constp x)))) | |
1506 (math-make-intv (nth 1 x) | |
1507 (calcFunc-log10 (nth 2 x)) | |
1508 (calcFunc-log10 (nth 3 x)))) | |
1509 ((math-infinitep x) | |
1510 (if (equal x '(var nan var-nan)) | |
1511 x | |
1512 '(var inf var-inf))) | |
1513 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1514 (list 'calcFunc-log10 x)))) |
40785 | 1515 |
1516 (defun calcFunc-log (x &optional b) ; [N N N] [Public] | |
1517 (cond ((or (null b) (equal b '(var e var-e))) | |
1518 (math-normalize (list 'calcFunc-ln x))) | |
1519 ((or (eq b 10) (equal b '(float 1 1))) | |
1520 (math-normalize (list 'calcFunc-log10 x))) | |
1521 ((math-zerop x) | |
1522 (if calc-infinite-mode | |
1523 (math-div (calcFunc-ln x) (calcFunc-ln b)) | |
1524 (math-reject-arg x "*Logarithm of zero"))) | |
1525 ((math-zerop b) | |
1526 (if calc-infinite-mode | |
1527 (math-div (calcFunc-ln x) (calcFunc-ln b)) | |
1528 (math-reject-arg b "*Logarithm of zero"))) | |
1529 ((math-equal-int b 1) | |
1530 (if calc-infinite-mode | |
1531 (math-div (calcFunc-ln x) 0) | |
1532 (math-reject-arg b "*Logarithm base one"))) | |
1533 ((math-equal-int x 1) | |
58475
647b2f6dac36
(math-nrf-n, math-nrf-nf, math-nrf-nfm1): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1534 (if (math-floatp b) '(float 0 0) 0)) |
40785 | 1535 ((and (Math-ratp x) (Math-ratp b) |
1536 (math-posp x) (math-posp b) | |
1537 (let* ((sign 1) (inv nil) | |
1538 (xx (if (Math-lessp 1 x) | |
1539 x | |
1540 (setq sign -1) | |
1541 (math-div 1 x))) | |
1542 (bb (if (Math-lessp 1 b) | |
1543 b | |
1544 (setq sign (- sign)) | |
1545 (math-div 1 b))) | |
1546 (res (if (Math-lessp xx bb) | |
1547 (setq inv (math-integer-log bb xx)) | |
1548 (math-integer-log xx bb)))) | |
1549 (and (car res) | |
1550 (setq x (if inv | |
1551 (math-div 1 (* sign (cdr res))) | |
1552 (* sign (cdr res))))))) | |
1553 x) | |
1554 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1555 ((and (Math-numberp x) (Math-numberp b)) | |
1556 (math-with-extra-prec 2 | |
1557 (math-div (math-ln-raw (math-float x)) | |
1558 (math-log-base-raw b)))) | |
1559 ((and (eq (car-safe x) 'sdev) | |
1560 (Math-numberp b)) | |
1561 (math-make-sdev (calcFunc-log (nth 1 x) b) | |
1562 (math-div (nth 2 x) | |
1563 (math-mul (nth 1 x) | |
1564 (math-log-base-raw b))))) | |
1565 ((and (eq (car-safe x) 'intv) (or (Math-posp (nth 2 x)) | |
1566 (not (math-intv-constp x))) | |
1567 (math-realp b)) | |
1568 (math-make-intv (nth 1 x) | |
1569 (calcFunc-log (nth 2 x) b) | |
1570 (calcFunc-log (nth 3 x) b))) | |
1571 ((or (eq (car-safe x) 'intv) (eq (car-safe b) 'intv)) | |
1572 (math-div (calcFunc-ln x) (calcFunc-ln b))) | |
1573 ((or (math-infinitep x) | |
1574 (math-infinitep b)) | |
1575 (math-div (calcFunc-ln x) (calcFunc-ln b))) | |
1576 (t (if (Math-numberp b) | |
1577 (calc-record-why 'numberp x) | |
1578 (calc-record-why 'numberp b)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1579 (list 'calcFunc-log x b)))) |
40785 | 1580 |
1581 (defun calcFunc-alog (x &optional b) | |
1582 (cond ((or (null b) (equal b '(var e var-e))) | |
1583 (math-normalize (list 'calcFunc-exp x))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1584 (t (math-pow b x)))) |
40785 | 1585 |
1586 (defun calcFunc-ilog (x b) | |
1587 (if (and (math-natnump x) (not (eq x 0)) | |
1588 (math-natnump b) (not (eq b 0))) | |
1589 (if (eq b 1) | |
1590 (math-reject-arg x "*Logarithm base one") | |
1591 (if (Math-natnum-lessp x b) | |
1592 0 | |
1593 (cdr (math-integer-log x b)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1594 (math-floor (calcFunc-log x b)))) |
40785 | 1595 |
1596 (defun math-integer-log (x b) | |
1597 (let ((pows (list b)) | |
1598 (pow (math-sqr b)) | |
1599 next | |
1600 sum n) | |
1601 (while (not (Math-lessp x pow)) | |
1602 (setq pows (cons pow pows) | |
1603 pow (math-sqr pow))) | |
1604 (setq n (lsh 1 (1- (length pows))) | |
1605 sum n | |
1606 pow (car pows)) | |
1607 (while (and (setq pows (cdr pows)) | |
1608 (Math-lessp pow x)) | |
1609 (setq n (/ n 2) | |
1610 next (math-mul pow (car pows))) | |
1611 (or (Math-lessp x next) | |
1612 (setq pow next | |
1613 sum (+ sum n)))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1614 (cons (equal pow x) sum))) |
40785 | 1615 |
1616 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41044
diff
changeset
|
1617 (defvar math-log-base-cache nil) |
40785 | 1618 (defun math-log-base-raw (b) ; [N N] |
1619 (if (not (and (equal (car math-log-base-cache) b) | |
1620 (eq (nth 1 math-log-base-cache) calc-internal-prec))) | |
1621 (setq math-log-base-cache (list b calc-internal-prec | |
1622 (math-ln-raw (math-float b))))) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1623 (nth 2 math-log-base-cache)) |
40785 | 1624 |
1625 (defun calcFunc-lnp1 (x) ; [N N] [Public] | |
1626 (cond ((Math-equal-int x -1) | |
1627 (if calc-infinite-mode | |
1628 '(neg (var inf var-inf)) | |
1629 (math-reject-arg x "*Logarithm of zero"))) | |
1630 ((eq x 0) 0) | |
1631 ((math-zerop x) '(float 0 0)) | |
1632 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1633 ((Math-numberp x) | |
1634 (math-with-extra-prec 2 | |
1635 (let ((x (math-float x))) | |
1636 (if (and (eq (car x) 'float) | |
1637 (math-lessp-float x '(float 5 -1)) | |
1638 (math-lessp-float '(float -5 -1) x)) | |
1639 (math-ln-plus-1-raw x) | |
1640 (math-ln-raw (math-add-float x '(float 1 0))))))) | |
1641 ((eq (car-safe x) 'sdev) | |
1642 (math-make-sdev (calcFunc-lnp1 (nth 1 x)) | |
1643 (math-div (nth 2 x) (math-add (nth 1 x) 1)))) | |
1644 ((and (eq (car-safe x) 'intv) (or (Math-posp (nth 2 x)) | |
1645 (not (math-intv-constp x)))) | |
1646 (math-make-intv (nth 1 x) | |
1647 (calcFunc-lnp1 (nth 2 x)) | |
1648 (calcFunc-lnp1 (nth 3 x)))) | |
1649 ((math-infinitep x) | |
1650 (if (equal x '(var nan var-nan)) | |
1651 x | |
1652 '(var inf var-inf))) | |
1653 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1654 (list 'calcFunc-lnp1 x)))) |
40785 | 1655 |
1656 (defun math-ln-raw (x) ; [N N] --- must be float format! | |
1657 (cond ((eq (car-safe x) 'cplx) | |
1658 (list 'cplx | |
1659 (math-mul-float (math-ln-raw | |
1660 (math-add-float (math-sqr-float (nth 1 x)) | |
1661 (math-sqr-float (nth 2 x)))) | |
1662 '(float 5 -1)) | |
1663 (math-arctan2-raw (nth 2 x) (nth 1 x)))) | |
1664 ((eq (car x) 'polar) | |
1665 (math-polar (list 'cplx | |
1666 (math-ln-raw (nth 1 x)) | |
1667 (math-to-radians (nth 2 x))))) | |
1668 ((Math-equal-int x 1) | |
1669 '(float 0 0)) | |
1670 (calc-symbolic-mode (signal 'inexact-result nil)) | |
1671 ((math-posp (nth 1 x)) ; positive and real | |
1672 (let ((xdigs (1- (math-numdigs (nth 1 x))))) | |
1673 (math-add-float (math-ln-raw-2 (list 'float (nth 1 x) (- xdigs))) | |
1674 (math-mul-float (math-float (+ (nth 2 x) xdigs)) | |
1675 (math-ln-10))))) | |
1676 ((math-zerop x) | |
1677 (math-reject-arg x "*Logarithm of zero")) | |
1678 ((eq calc-complex-mode 'polar) ; negative and real | |
1679 (math-polar | |
1680 (list 'cplx ; negative and real | |
1681 (math-ln-raw (math-neg-float x)) | |
1682 (math-pi)))) | |
1683 (t (list 'cplx ; negative and real | |
1684 (math-ln-raw (math-neg-float x)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1685 (math-pi))))) |
40785 | 1686 |
1687 (defun math-ln-raw-2 (x) ; [F F] | |
1688 (cond ((math-lessp-float '(float 14 -1) x) | |
1689 (math-add-float (math-ln-raw-2 (math-mul-float x '(float 5 -1))) | |
1690 (math-ln-2))) | |
1691 (t ; now .7 < x <= 1.4 | |
1692 (math-ln-raw-3 (math-div-float (math-sub-float x '(float 1 0)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1693 (math-add-float x '(float 1 0))))))) |
40785 | 1694 |
1695 (defun math-ln-raw-3 (x) ; [F F] | |
1696 (math-mul-float (math-ln-raw-series x 3 x (math-sqr-float x)) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1697 '(float 2 0))) |
40785 | 1698 |
1699 ;;; Compute ln((1+x)/(1-x)) | |
1700 (defun math-ln-raw-series (sum n x xsqr) | |
1701 (math-working "log" sum) | |
1702 (let* ((nextx (math-mul-float x xsqr)) | |
1703 (nextsum (math-add-float sum (math-div-float nextx (math-float n))))) | |
1704 (if (math-nearly-equal-float sum nextsum) | |
1705 sum | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1706 (math-ln-raw-series nextsum (+ n 2) nextx xsqr)))) |
40785 | 1707 |
1708 (defun math-ln-plus-1-raw (x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1709 (math-lnp1-series x 2 x (math-neg x))) |
40785 | 1710 |
1711 (defun math-lnp1-series (sum n xpow x) | |
1712 (math-working "lnp1" sum) | |
1713 (let* ((nextx (math-mul-float xpow x)) | |
1714 (nextsum (math-add-float sum (math-div-float nextx (math-float n))))) | |
1715 (if (math-nearly-equal-float sum nextsum) | |
1716 sum | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1717 (math-lnp1-series nextsum (1+ n) nextx x)))) |
40785 | 1718 |
1719 (math-defcache math-ln-10 (float (bigpos 018 684 045 994 092 585 302 2) -21) | |
1720 (math-ln-raw-2 '(float 1 1))) | |
1721 | |
1722 (math-defcache math-ln-2 (float (bigpos 417 309 945 559 180 147 693) -21) | |
1723 (math-ln-raw-3 (math-float '(frac 1 3)))) | |
1724 | |
1725 | |
1726 | |
1727 ;;; Hyperbolic functions. | |
1728 | |
1729 (defun calcFunc-sinh (x) ; [N N] [Public] | |
1730 (cond ((eq x 0) 0) | |
1731 (math-expand-formulas | |
1732 (math-normalize | |
1733 (list '/ (list '- (list 'calcFunc-exp x) | |
1734 (list 'calcFunc-exp (list 'neg x))) 2))) | |
1735 ((Math-numberp x) | |
1736 (if calc-symbolic-mode (signal 'inexact-result nil)) | |
1737 (math-with-extra-prec 2 | |
1738 (let ((expx (math-exp-raw (math-float x)))) | |
1739 (math-mul (math-add expx (math-div -1 expx)) '(float 5 -1))))) | |
1740 ((eq (car-safe x) 'sdev) | |
1741 (math-make-sdev (calcFunc-sinh (nth 1 x)) | |
1742 (math-mul (nth 2 x) (calcFunc-cosh (nth 1 x))))) | |
1743 ((eq (car x) 'intv) | |
1744 (math-sort-intv (nth 1 x) | |
1745 (calcFunc-sinh (nth 2 x)) | |
1746 (calcFunc-sinh (nth 3 x)))) | |
1747 ((or (equal x '(var inf var-inf)) | |
1748 (equal x '(neg (var inf var-inf))) | |
1749 (equal x '(var nan var-nan))) | |
1750 x) | |
1751 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1752 (list 'calcFunc-sinh x)))) |
40785 | 1753 (put 'calcFunc-sinh 'math-expandable t) |
1754 | |
1755 (defun calcFunc-cosh (x) ; [N N] [Public] | |
1756 (cond ((eq x 0) 1) | |
1757 (math-expand-formulas | |
1758 (math-normalize | |
1759 (list '/ (list '+ (list 'calcFunc-exp x) | |
1760 (list 'calcFunc-exp (list 'neg x))) 2))) | |
1761 ((Math-numberp x) | |
1762 (if calc-symbolic-mode (signal 'inexact-result nil)) | |
1763 (math-with-extra-prec 2 | |
1764 (let ((expx (math-exp-raw (math-float x)))) | |
1765 (math-mul (math-add expx (math-div 1 expx)) '(float 5 -1))))) | |
1766 ((eq (car-safe x) 'sdev) | |
1767 (math-make-sdev (calcFunc-cosh (nth 1 x)) | |
1768 (math-mul (nth 2 x) | |
1769 (calcFunc-sinh (nth 1 x))))) | |
1770 ((and (eq (car x) 'intv) (math-intv-constp x)) | |
1771 (setq x (math-abs x)) | |
1772 (math-sort-intv (nth 1 x) | |
1773 (calcFunc-cosh (nth 2 x)) | |
1774 (calcFunc-cosh (nth 3 x)))) | |
1775 ((or (equal x '(var inf var-inf)) | |
1776 (equal x '(neg (var inf var-inf))) | |
1777 (equal x '(var nan var-nan))) | |
1778 (math-abs x)) | |
1779 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1780 (list 'calcFunc-cosh x)))) |
40785 | 1781 (put 'calcFunc-cosh 'math-expandable t) |
1782 | |
1783 (defun calcFunc-tanh (x) ; [N N] [Public] | |
1784 (cond ((eq x 0) 0) | |
1785 (math-expand-formulas | |
1786 (math-normalize | |
1787 (let ((expx (list 'calcFunc-exp x)) | |
1788 (expmx (list 'calcFunc-exp (list 'neg x)))) | |
1789 (math-normalize | |
1790 (list '/ (list '- expx expmx) (list '+ expx expmx)))))) | |
1791 ((Math-numberp x) | |
1792 (if calc-symbolic-mode (signal 'inexact-result nil)) | |
1793 (math-with-extra-prec 2 | |
1794 (let* ((expx (calcFunc-exp (math-float x))) | |
1795 (expmx (math-div 1 expx))) | |
1796 (math-div (math-sub expx expmx) | |
1797 (math-add expx expmx))))) | |
1798 ((eq (car-safe x) 'sdev) | |
1799 (math-make-sdev (calcFunc-tanh (nth 1 x)) | |
1800 (math-div (nth 2 x) | |
1801 (math-sqr (calcFunc-cosh (nth 1 x)))))) | |
1802 ((eq (car x) 'intv) | |
1803 (math-sort-intv (nth 1 x) | |
1804 (calcFunc-tanh (nth 2 x)) | |
1805 (calcFunc-tanh (nth 3 x)))) | |
1806 ((equal x '(var inf var-inf)) | |
1807 1) | |
1808 ((equal x '(neg (var inf var-inf))) | |
1809 -1) | |
1810 ((equal x '(var nan var-nan)) | |
1811 x) | |
1812 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1813 (list 'calcFunc-tanh x)))) |
40785 | 1814 (put 'calcFunc-tanh 'math-expandable t) |
1815 | |
60079
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1816 (defun calcFunc-sech (x) ; [N N] [Public] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1817 (cond ((eq x 0) 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1818 (math-expand-formulas |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1819 (math-normalize |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1820 (list '/ 2 (list '+ (list 'calcFunc-exp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1821 (list 'calcFunc-exp (list 'neg x)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1822 ((Math-numberp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1823 (if calc-symbolic-mode (signal 'inexact-result nil)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1824 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1825 (let ((expx (math-exp-raw (math-float x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1826 (math-div '(float 2 0) (math-add expx (math-div 1 expx)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1827 ((eq (car-safe x) 'sdev) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1828 (math-make-sdev (calcFunc-sech (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1829 (math-mul (nth 2 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1830 (math-mul (calcFunc-sech (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1831 (calcFunc-tanh (nth 1 x)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1832 ((and (eq (car x) 'intv) (math-intv-constp x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1833 (setq x (math-abs x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1834 (math-sort-intv (nth 1 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1835 (calcFunc-sech (nth 2 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1836 (calcFunc-sech (nth 3 x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1837 ((or (equal x '(var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1838 (equal x '(neg (var inf var-inf)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1839 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1840 ((equal x '(var nan var-nan)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1841 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1842 (t (calc-record-why 'numberp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1843 (list 'calcFunc-sech x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1844 (put 'calcFunc-sech 'math-expandable t) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1845 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1846 (defun calcFunc-csch (x) ; [N N] [Public] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1847 (cond ((eq x 0) (math-div 1 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1848 (math-expand-formulas |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1849 (math-normalize |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1850 (list '/ 2 (list '- (list 'calcFunc-exp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1851 (list 'calcFunc-exp (list 'neg x)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1852 ((Math-numberp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1853 (if calc-symbolic-mode (signal 'inexact-result nil)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1854 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1855 (let ((expx (math-exp-raw (math-float x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1856 (math-div '(float 2 0) (math-add expx (math-div -1 expx)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1857 ((eq (car-safe x) 'sdev) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1858 (math-make-sdev (calcFunc-csch (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1859 (math-mul (nth 2 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1860 (math-mul (calcFunc-csch (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1861 (calcFunc-coth (nth 1 x)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1862 ((eq (car x) 'intv) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1863 (if (and (Math-negp (nth 2 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1864 (Math-posp (nth 3 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1865 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1866 (math-sort-intv (nth 1 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1867 (calcFunc-csch (nth 2 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1868 (calcFunc-csch (nth 3 x))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1869 ((or (equal x '(var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1870 (equal x '(neg (var inf var-inf)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1871 0) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1872 ((equal x '(var nan var-nan)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1873 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1874 (t (calc-record-why 'numberp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1875 (list 'calcFunc-csch x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1876 (put 'calcFunc-csch 'math-expandable t) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1877 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1878 (defun calcFunc-coth (x) ; [N N] [Public] |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1879 (cond ((eq x 0) (math-div 1 0)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1880 (math-expand-formulas |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1881 (math-normalize |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1882 (let ((expx (list 'calcFunc-exp x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1883 (expmx (list 'calcFunc-exp (list 'neg x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1884 (math-normalize |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1885 (list '/ (list '+ expx expmx) (list '- expx expmx)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1886 ((Math-numberp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1887 (if calc-symbolic-mode (signal 'inexact-result nil)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1888 (math-with-extra-prec 2 |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1889 (let* ((expx (calcFunc-exp (math-float x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1890 (expmx (math-div 1 expx))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1891 (math-div (math-add expx expmx) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1892 (math-sub expx expmx))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1893 ((eq (car-safe x) 'sdev) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1894 (math-make-sdev (calcFunc-coth (nth 1 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1895 (math-div (nth 2 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1896 (math-sqr (calcFunc-sinh (nth 1 x)))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1897 ((eq (car x) 'intv) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1898 (if (and (Math-negp (nth 2 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1899 (Math-posp (nth 3 x))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1900 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1901 (math-sort-intv (nth 1 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1902 (calcFunc-coth (nth 2 x)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1903 (calcFunc-coth (nth 3 x))))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1904 ((equal x '(var inf var-inf)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1905 1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1906 ((equal x '(neg (var inf var-inf))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1907 -1) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1908 ((equal x '(var nan var-nan)) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1909 x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1910 (t (calc-record-why 'numberp x) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1911 (list 'calcFunc-coth x)))) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1912 (put 'calcFunc-coth 'math-expandable t) |
b676ef11ff65
(calc-sec, calc-csc, calc-cot, calc-sech, calc-csch, calc-coth)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58663
diff
changeset
|
1913 |
40785 | 1914 (defun calcFunc-arcsinh (x) ; [N N] [Public] |
1915 (cond ((eq x 0) 0) | |
1916 (math-expand-formulas | |
1917 (math-normalize | |
1918 (list 'calcFunc-ln (list '+ x (list 'calcFunc-sqrt | |
1919 (list '+ (list '^ x 2) 1)))))) | |
1920 ((Math-numberp x) | |
1921 (if calc-symbolic-mode (signal 'inexact-result nil)) | |
1922 (math-with-extra-prec 2 | |
1923 (math-ln-raw (math-add x (math-sqrt-raw (math-add (math-sqr x) | |
1924 '(float 1 0))))))) | |
1925 ((eq (car-safe x) 'sdev) | |
1926 (math-make-sdev (calcFunc-arcsinh (nth 1 x)) | |
1927 (math-div (nth 2 x) | |
1928 (math-sqrt | |
1929 (math-add (math-sqr (nth 1 x)) 1))))) | |
1930 ((eq (car x) 'intv) | |
1931 (math-sort-intv (nth 1 x) | |
1932 (calcFunc-arcsinh (nth 2 x)) | |
1933 (calcFunc-arcsinh (nth 3 x)))) | |
1934 ((or (equal x '(var inf var-inf)) | |
1935 (equal x '(neg (var inf var-inf))) | |
1936 (equal x '(var nan var-nan))) | |
1937 x) | |
1938 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1939 (list 'calcFunc-arcsinh x)))) |
40785 | 1940 (put 'calcFunc-arcsinh 'math-expandable t) |
1941 | |
1942 (defun calcFunc-arccosh (x) ; [N N] [Public] | |
1943 (cond ((eq x 1) 0) | |
1944 ((and (eq x -1) calc-symbolic-mode) | |
1945 '(var pi var-pi)) | |
1946 ((and (eq x 0) calc-symbolic-mode) | |
1947 (math-div (math-mul '(var pi var-pi) '(var i var-i)) 2)) | |
1948 (math-expand-formulas | |
1949 (math-normalize | |
1950 (list 'calcFunc-ln (list '+ x (list 'calcFunc-sqrt | |
1951 (list '- (list '^ x 2) 1)))))) | |
1952 ((Math-numberp x) | |
1953 (if calc-symbolic-mode (signal 'inexact-result nil)) | |
1954 (if (Math-equal-int x -1) | |
1955 (math-imaginary (math-pi)) | |
1956 (math-with-extra-prec 2 | |
1957 (if (or t ; need to do this even in the real case! | |
1958 (memq (car-safe x) '(cplx polar))) | |
1959 (let ((xp1 (math-add 1 x))) ; this gets the branch cuts right | |
1960 (math-ln-raw | |
1961 (math-add x (math-mul xp1 | |
1962 (math-sqrt-raw | |
1963 (math-div (math-sub | |
1964 x | |
1965 '(float 1 0)) | |
1966 xp1)))))) | |
1967 (math-ln-raw | |
1968 (math-add x (math-sqrt-raw (math-add (math-sqr x) | |
1969 '(float -1 0))))))))) | |
1970 ((eq (car-safe x) 'sdev) | |
1971 (math-make-sdev (calcFunc-arccosh (nth 1 x)) | |
1972 (math-div (nth 2 x) | |
1973 (math-sqrt | |
1974 (math-add (math-sqr (nth 1 x)) -1))))) | |
1975 ((eq (car x) 'intv) | |
1976 (math-sort-intv (nth 1 x) | |
1977 (calcFunc-arccosh (nth 2 x)) | |
1978 (calcFunc-arccosh (nth 3 x)))) | |
1979 ((or (equal x '(var inf var-inf)) | |
1980 (equal x '(neg (var inf var-inf))) | |
1981 (equal x '(var nan var-nan))) | |
1982 x) | |
1983 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1984 (list 'calcFunc-arccosh x)))) |
40785 | 1985 (put 'calcFunc-arccosh 'math-expandable t) |
1986 | |
1987 (defun calcFunc-arctanh (x) ; [N N] [Public] | |
1988 (cond ((eq x 0) 0) | |
1989 ((and (Math-equal-int x 1) calc-infinite-mode) | |
1990 '(var inf var-inf)) | |
1991 ((and (Math-equal-int x -1) calc-infinite-mode) | |
1992 '(neg (var inf var-inf))) | |
1993 (math-expand-formulas | |
1994 (list '/ (list '- | |
1995 (list 'calcFunc-ln (list '+ 1 x)) | |
1996 (list 'calcFunc-ln (list '- 1 x))) 2)) | |
1997 ((Math-numberp x) | |
1998 (if calc-symbolic-mode (signal 'inexact-result nil)) | |
1999 (math-with-extra-prec 2 | |
2000 (if (or (memq (car-safe x) '(cplx polar)) | |
2001 (Math-lessp 1 x)) | |
2002 (math-mul (math-sub (math-ln-raw (math-add '(float 1 0) x)) | |
2003 (math-ln-raw (math-sub '(float 1 0) x))) | |
2004 '(float 5 -1)) | |
2005 (if (and (math-equal-int x 1) calc-infinite-mode) | |
2006 '(var inf var-inf) | |
2007 (if (and (math-equal-int x -1) calc-infinite-mode) | |
2008 '(neg (var inf var-inf)) | |
2009 (math-mul (math-ln-raw (math-div (math-add '(float 1 0) x) | |
2010 (math-sub 1 x))) | |
2011 '(float 5 -1))))))) | |
2012 ((eq (car-safe x) 'sdev) | |
2013 (math-make-sdev (calcFunc-arctanh (nth 1 x)) | |
2014 (math-div (nth 2 x) | |
2015 (math-sub 1 (math-sqr (nth 1 x)))))) | |
2016 ((eq (car x) 'intv) | |
2017 (math-sort-intv (nth 1 x) | |
2018 (calcFunc-arctanh (nth 2 x)) | |
2019 (calcFunc-arctanh (nth 3 x)))) | |
2020 ((equal x '(var nan var-nan)) | |
2021 x) | |
2022 (t (calc-record-why 'numberp x) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2023 (list 'calcFunc-arctanh x)))) |
40785 | 2024 (put 'calcFunc-arctanh 'math-expandable t) |
2025 | |
2026 | |
2027 ;;; Convert A from HMS or degrees to radians. | |
2028 (defun calcFunc-rad (a) ; [R R] [Public] | |
2029 (cond ((or (Math-numberp a) | |
2030 (eq (car a) 'intv)) | |
2031 (math-with-extra-prec 2 | |
2032 (math-mul a (math-pi-over-180)))) | |
2033 ((eq (car a) 'hms) | |
2034 (math-from-hms a 'rad)) | |
2035 ((eq (car a) 'sdev) | |
2036 (math-make-sdev (calcFunc-rad (nth 1 a)) | |
2037 (calcFunc-rad (nth 2 a)))) | |
2038 (math-expand-formulas | |
2039 (math-div (math-mul a '(var pi var-pi)) 180)) | |
2040 ((math-infinitep a) a) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2041 (t (list 'calcFunc-rad a)))) |
40785 | 2042 (put 'calcFunc-rad 'math-expandable t) |
2043 | |
2044 ;;; Convert A from HMS or radians to degrees. | |
2045 (defun calcFunc-deg (a) ; [R R] [Public] | |
2046 (cond ((or (Math-numberp a) | |
2047 (eq (car a) 'intv)) | |
2048 (math-with-extra-prec 2 | |
2049 (math-div a (math-pi-over-180)))) | |
2050 ((eq (car a) 'hms) | |
2051 (math-from-hms a 'deg)) | |
2052 ((eq (car a) 'sdev) | |
2053 (math-make-sdev (calcFunc-deg (nth 1 a)) | |
2054 (calcFunc-deg (nth 2 a)))) | |
2055 (math-expand-formulas | |
2056 (math-div (math-mul 180 a) '(var pi var-pi))) | |
2057 ((math-infinitep a) a) | |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2058 (t (list 'calcFunc-deg a)))) |
40785 | 2059 (put 'calcFunc-deg 'math-expandable t) |
2060 | |
58663
7ed196c06460
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58475
diff
changeset
|
2061 (provide 'calc-math) |
7ed196c06460
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58475
diff
changeset
|
2062 |
52401 | 2063 ;;; arch-tag: c7367e8e-d0b8-4f70-8577-2fb3f31dbb4c |
41044
4549dec29728
(calcFunc-sqrt, calcFunc-hypot): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2064 ;;; calc-math.el ends here |