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