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