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