annotate lisp/calc/calc-arith.el @ 102945:f623dc25d37e

(get_adstyle_property): Fix previous change.
author Kenichi Handa <handa@m17n.org>
date Mon, 13 Apr 2009 12:37:41 +0000
parents a9dc0e7c3f2b
children 1d1d5d9bd884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
1 ;;; calc-arith.el --- arithmetic functions for Calc
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
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,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94654
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
5
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
76595
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
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
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
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
24 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
26 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; This file is autoloaded from calc-ext.el.
58647
e655efbeebac Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58626
diff changeset
29
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
33 ;;; The following lists are not exhaustive.
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
34 (defvar math-scalar-functions '(calcFunc-det
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
35 calcFunc-cnorm calcFunc-rnorm
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
36 calcFunc-vlen calcFunc-vcount
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
37 calcFunc-vsum calcFunc-vprod
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
38 calcFunc-vmin calcFunc-vmax))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
39
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
40 (defvar math-nonscalar-functions '(vec calcFunc-idn calcFunc-diag
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
41 calcFunc-cvec calcFunc-index
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
42 calcFunc-trn
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
43 | calcFunc-append
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
44 calcFunc-cons calcFunc-rcons
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
45 calcFunc-tail calcFunc-rhead))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
46
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
47 (defvar math-scalar-if-args-functions '(+ - * / neg))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
48
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
49 (defvar math-real-functions '(calcFunc-arg
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
50 calcFunc-re calcFunc-im
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
51 calcFunc-floor calcFunc-ceil
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
52 calcFunc-trunc calcFunc-round
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
53 calcFunc-rounde calcFunc-roundu
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
54 calcFunc-ffloor calcFunc-fceil
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
55 calcFunc-ftrunc calcFunc-fround
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
56 calcFunc-frounde calcFunc-froundu))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
57
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
58 (defvar math-positive-functions '())
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
59
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
60 (defvar math-nonnegative-functions '(calcFunc-cnorm calcFunc-rnorm
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
61 calcFunc-vlen calcFunc-vcount))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
62
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
63 (defvar math-real-scalar-functions '(% calcFunc-idiv calcFunc-abs
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
64 calcFunc-choose calcFunc-perm
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
65 calcFunc-eq calcFunc-neq
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
66 calcFunc-lt calcFunc-gt
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
67 calcFunc-leq calcFunc-geq
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
68 calcFunc-lnot
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
69 calcFunc-max calcFunc-min))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
70
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
71 (defvar math-real-if-arg-functions '(calcFunc-sin calcFunc-cos
60077
14957017dad7 (math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58688
diff changeset
72 calcFunc-tan calcFunc-sec
14957017dad7 (math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58688
diff changeset
73 calcFunc-csc calcFunc-cot
14957017dad7 (math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58688
diff changeset
74 calcFunc-arctan
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
75 calcFunc-sinh calcFunc-cosh
60077
14957017dad7 (math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58688
diff changeset
76 calcFunc-tanh calcFunc-sech
14957017dad7 (math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58688
diff changeset
77 calcFunc-csch calcFunc-coth
14957017dad7 (math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58688
diff changeset
78 calcFunc-exp
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
79 calcFunc-gamma calcFunc-fact))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
80
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
81 (defvar math-integer-functions '(calcFunc-idiv
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
82 calcFunc-isqrt calcFunc-ilog
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
83 calcFunc-vlen calcFunc-vcount))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
84
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
85 (defvar math-num-integer-functions '())
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
86
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
87 (defvar math-rounding-functions '(calcFunc-floor
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
88 calcFunc-ceil
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
89 calcFunc-round calcFunc-trunc
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
90 calcFunc-rounde calcFunc-roundu))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
91
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
92 (defvar math-float-rounding-functions '(calcFunc-ffloor
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
93 calcFunc-fceil
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
94 calcFunc-fround calcFunc-ftrunc
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
95 calcFunc-frounde calcFunc-froundu))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
96
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
97 (defvar math-integer-if-args-functions '(+ - * % neg calcFunc-abs
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
98 calcFunc-min calcFunc-max
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
99 calcFunc-choose calcFunc-perm))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
100
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 ;;; Arithmetic.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (defun calc-min (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
105 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
107 (calc-binary-op "min" 'calcFunc-min arg '(var inf var-inf))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (defun calc-max (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
111 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
112 (calc-binary-op "max" 'calcFunc-max arg '(neg (var inf var-inf)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
113
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 (defun calc-abs (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
117 (calc-unary-op "abs" 'calcFunc-abs arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (defun calc-idiv (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
123 (calc-binary-op "\\" 'calcFunc-idiv arg 1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (defun calc-floor (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 (if (calc-is-inverse)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (if (calc-is-hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (calc-unary-op "ceil" 'calcFunc-fceil arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (calc-unary-op "ceil" 'calcFunc-ceil arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 (if (calc-is-hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (calc-unary-op "flor" 'calcFunc-ffloor arg)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
135 (calc-unary-op "flor" 'calcFunc-floor arg)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 (defun calc-ceiling (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (calc-invert-func)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
140 (calc-floor arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (defun calc-round (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145 (if (calc-is-inverse)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 (if (calc-is-hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 (calc-unary-op "trnc" 'calcFunc-ftrunc arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148 (calc-unary-op "trnc" 'calcFunc-trunc arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (if (calc-is-hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (calc-unary-op "rond" 'calcFunc-fround arg)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
151 (calc-unary-op "rond" 'calcFunc-round arg)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 (defun calc-trunc (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 (calc-invert-func)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
156 (calc-round arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
157
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
158 (defun calc-mant-part (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
159 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
160 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
161 (calc-unary-op "mant" 'calcFunc-mant arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
162
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
163 (defun calc-xpon-part (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
164 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
165 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
166 (calc-unary-op "xpon" 'calcFunc-xpon arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
167
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
168 (defun calc-scale-float (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
169 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
171 (calc-binary-op "scal" 'calcFunc-scf arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 (defun calc-abssqr (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
176 (calc-unary-op "absq" 'calcFunc-abssqr arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
177
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178 (defun calc-sign (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (calc-slow-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
181 (calc-unary-op "sign" 'calcFunc-sign arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
182
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
183 (defun calc-increment (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (calc-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
186 (calc-enter-result 1 "incr" (list 'calcFunc-incr (calc-top-n 1) arg))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (defun calc-decrement (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
190 (calc-wrapper
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
191 (calc-enter-result 1 "decr" (list 'calcFunc-decr (calc-top-n 1) arg))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (defun math-abs-approx (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (cond ((Math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (math-neg a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 ((Math-anglep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 ((eq (car a) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 (math-add (math-abs (nth 1 a)) (math-abs (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
201 ((eq (car a) 'polar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203 ((eq (car a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 (math-abs-approx (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
206 (math-max (math-abs (nth 2 a)) (math-abs (nth 3 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 ((eq (car a) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 ((eq (car a) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210 (math-reduce-vec 'math-add-abs-approx a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211 ((eq (car a) 'calcFunc-abs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212 (car a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
213 (t a)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
215 (defun math-add-abs-approx (a b)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
216 (math-add (math-abs-approx a) (math-abs-approx b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
218
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219 ;;;; Declarations.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
221 (defvar math-decls-cache-tag nil)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
222 (defvar math-decls-cache nil)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
223 (defvar math-decls-all nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 ;;; Math-decls-cache is an a-list where each entry is a list of the form:
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
226 ;;; (VAR TYPES RANGE)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
227 ;;; where VAR is a variable name (with var- prefix) or function name;
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
228 ;;; TYPES is a list of type symbols (any, int, frac, ...)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
229 ;;; RANGE is a sorted vector of intervals describing the range.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
231 (defvar math-super-types
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
232 '((int numint rat real number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
233 (numint real number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
234 (frac rat real number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
235 (rat real number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
236 (float real number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
237 (real number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
238 (number)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
239 (scalar)
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
240 (sqmatrix matrix vector)
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
241 (matrix vector)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
242 (vector)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
243 (const)))
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
244
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
245 (defun math-setup-declarations ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
246 (or (eq math-decls-cache-tag (calc-var-value 'var-Decls))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
247 (let ((p (calc-var-value 'var-Decls))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
248 vec type range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
249 (setq math-decls-cache-tag p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
250 math-decls-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251 (and (eq (car-safe p) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 (while (setq p (cdr p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253 (and (eq (car-safe (car p)) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254 (setq vec (nth 2 (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255 (condition-case err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256 (let ((v (nth 1 (car p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257 (setq type nil range nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 (or (eq (car-safe vec) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
259 (setq vec (list 'vec vec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260 (while (and (setq vec (cdr vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 (not (Math-objectp (car vec))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
262 (and (eq (car-safe (car vec)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 (let ((st (assq (nth 1 (car vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264 math-super-types)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 (cond (st (setq type (append type st)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 ((eq (nth 1 (car vec)) 'pos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 (setq type (append type
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
268 '(real number))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
269 range
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
270 '(intv 1 0 (var inf var-inf))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271 ((eq (nth 1 (car vec)) 'nonneg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272 (setq type (append type
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273 '(real number))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
274 range
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
275 '(intv 3 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276 (var inf var-inf))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
277 (if vec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
278 (setq type (append type '(real number))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 range (math-prepare-set (cons 'vec vec))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 (setq type (list type range))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (or (eq (car-safe v) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 (setq v (list 'vec v)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 (while (setq v (cdr v))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 (if (or (eq (car-safe (car v)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (not (Math-primp (car v))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 (setq math-decls-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 (cons (cons (if (eq (car (car v)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 (nth 2 (car v))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 (car (car v)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 type)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 math-decls-cache)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (error nil)))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
293 (setq math-decls-all (assq 'var-All math-decls-cache)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (defun math-known-scalarp (a &optional assume-scalar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (math-setup-declarations)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 (if (if calc-matrix-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (eq calc-matrix-mode 'scalar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 assume-scalar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (not (math-check-known-matrixp a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
301 (math-check-known-scalarp a)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (defun math-known-matrixp (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (and (not (Math-scalarp a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
305 (not (math-known-scalarp a t))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306
65899
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
307 (defun math-known-square-matrixp (a)
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
308 (and (math-known-matrixp a)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
309 (math-check-known-square-matrixp a)))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
310
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 ;;; Try to prove that A is a scalar (i.e., a non-vector).
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 (defun math-check-known-scalarp (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 (cond ((Math-objectp a) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 ((memq (car a) math-scalar-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 ((memq (car a) math-real-scalar-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317 t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318 ((memq (car a) math-scalar-if-args-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 (while (and (setq a (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320 (math-check-known-scalarp (car a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 (null a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 ((eq (car a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (math-check-known-scalarp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 ((math-const-var a) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 (let ((decl (if (eq (car a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 (or (assq (nth 2 a) math-decls-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 math-decls-all)
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
329 (assq (car a) math-decls-cache)))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
330 val)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
331 (cond
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
332 ((memq 'scalar (nth 1 decl))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
333 t)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
334 ((and (eq (car a) 'var)
68895
ab08676bc819 (math-check-known-scalarp): Make sure expression is a symbol before
Jay Belanger <jay.p.belanger@gmail.com>
parents: 68860
diff changeset
335 (symbolp (nth 2 a))
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
336 (boundp (nth 2 a))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
337 (setq val (symbol-value (nth 2 a))))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
338 (math-check-known-scalarp val))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
339 (t
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
340 nil))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 ;;; Try to prove that A is *not* a scalar.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (defun math-check-known-matrixp (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 (cond ((Math-objectp a) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345 ((memq (car a) math-nonscalar-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346 t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
347 ((memq (car a) math-scalar-if-args-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
348 (while (and (setq a (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349 (not (math-check-known-matrixp (car a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
350 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351 ((eq (car a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
352 (math-check-known-matrixp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 ((math-const-var a) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (let ((decl (if (eq (car a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356 (or (assq (nth 2 a) math-decls-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 math-decls-all)
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
358 (assq (car a) math-decls-cache)))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
359 val)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
360 (cond
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
361 ((memq 'matrix (nth 1 decl))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
362 t)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
363 ((and (eq (car a) 'var)
68860
34704dae6f60 (math-check-known-matrixp): Make sure expression is a symbol before
Jay Belanger <jay.p.belanger@gmail.com>
parents: 68636
diff changeset
364 (symbolp (nth 2 a))
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
365 (boundp (nth 2 a))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
366 (setq val (symbol-value (nth 2 a))))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
367 (math-check-known-matrixp val))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
368 (t
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
369 nil))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
371 ;;; Given that A is a matrix, try to prove that it is a square matrix.
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
372 (defun math-check-known-square-matrixp (a)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
373 (cond ((math-square-matrixp a)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
374 t)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
375 ((eq (car-safe a) '^)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
376 (math-check-known-square-matrixp (nth 1 a)))
66770
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
377 ((or
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
378 (eq (car-safe a) '*)
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
379 (eq (car-safe a) '+)
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
380 (eq (car-safe a) '-))
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
381 (and
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
382 (math-check-known-square-matrixp (nth 1 a))
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
383 (math-check-known-square-matrixp (nth 2 a))))
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
384 (t
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
385 (let ((decl (if (eq (car a) 'var)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
386 (or (assq (nth 2 a) math-decls-cache)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
387 math-decls-all)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
388 (assq (car a) math-decls-cache)))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
389 val)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
390 (cond
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
391 ((memq 'sqmatrix (nth 1 decl))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
392 t)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
393 ((and (eq (car a) 'var)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
394 (boundp (nth 2 a))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
395 (setq val (symbol-value (nth 2 a))))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
396 (math-check-known-square-matrixp val))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
397 ((and (or
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
398 (integerp calc-matrix-mode)
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
399 (eq calc-matrix-mode 'sqmatrix))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
400 (eq (car-safe a) 'var))
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
401 t)
65993
7e915ad64a71 (math-check-known-square-matrixp): Change order in which value is checked.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65987
diff changeset
402 ((memq 'matrix (nth 1 decl))
7e915ad64a71 (math-check-known-square-matrixp): Change order in which value is checked.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65987
diff changeset
403 nil)
65987
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
404 (t
16a03d245dee (math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65899
diff changeset
405 nil))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407 ;;; Try to prove that A is a real (i.e., not complex).
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 (defun math-known-realp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
409 (< (math-possible-signs a) 8))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 ;;; Try to prove that A is real and positive.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412 (defun math-known-posp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
413 (eq (math-possible-signs a) 4))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
415 ;;; Try to prove that A is real and negative.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 (defun math-known-negp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
417 (eq (math-possible-signs a) 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
419 ;;; Try to prove that A is real and nonnegative.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420 (defun math-known-nonnegp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
421 (memq (math-possible-signs a) '(2 4 6)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
422
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
423 ;;; Try to prove that A is real and nonpositive.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
424 (defun math-known-nonposp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
425 (memq (math-possible-signs a) '(1 2 3)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
426
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
427 ;;; Try to prove that A is nonzero.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
428 (defun math-known-nonzerop (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
429 (memq (math-possible-signs a) '(1 4 5 8 9 12 13)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
430
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
431 ;;; Return true if A is negative, or looks negative but we don't know.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
432 (defun math-guess-if-neg (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (let ((sgn (math-possible-signs a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 (if (memq sgn '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 (if (memq sgn '(2 4 6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 nil
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
438 (math-looks-negp a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 ;;; Find the possible signs of A, assuming A is a number of some kind.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 ;;; Returns an integer with bits: 1 may be negative,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442 ;;; 2 may be zero,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 ;;; 4 may be positive,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 ;;; 8 may be nonreal.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (defun math-possible-signs (a &optional origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447 (cond ((Math-objectp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (if origin (setq a (math-sub a origin)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (cond ((Math-posp a) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 ((Math-negp a) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 ((Math-zerop a) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 ((eq (car a) 'intv)
58688
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
453 (cond
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
454 ((math-known-posp (nth 2 a)) 4)
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
455 ((math-known-negp (nth 3 a)) 1)
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
456 ((Math-zerop (nth 2 a)) 6)
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
457 ((Math-zerop (nth 3 a)) 3)
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
458 (t 7)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459 ((eq (car a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
460 (if (math-known-realp (nth 1 a)) 7 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (t 8)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462 ((memq (car a) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 (cond ((Math-realp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (if (eq (car a) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (math-neg-signs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466 (math-possible-signs (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467 (if origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
468 (math-add origin (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
469 (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
470 (math-possible-signs (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471 (if origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
472 (math-sub origin (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
473 (math-neg (nth 1 a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474 ((Math-realp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475 (let ((org (if (eq (car a) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476 (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 (math-neg (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
478 (math-possible-signs (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
479 (if origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 (math-add origin org)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
481 org))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
482 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
483 (let ((s1 (math-possible-signs (nth 1 a) origin))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
484 (s2 (math-possible-signs (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
485 (if (eq (car a) '-) (setq s2 (math-neg-signs s2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
486 (cond ((eq s1 s2) s1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
487 ((eq s1 2) s2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488 ((eq s2 2) s1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
489 ((>= s1 8) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
490 ((>= s2 8) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
491 ((and (eq s1 4) (eq s2 6)) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
492 ((and (eq s2 4) (eq s1 6)) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
493 ((and (eq s1 1) (eq s2 3)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
494 ((and (eq s2 1) (eq s1 3)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495 (t 7))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 ((eq (car a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 (math-neg-signs (math-possible-signs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
498 (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (and origin (math-neg origin)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 ((and origin (Math-zerop origin) (setq origin nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
502 ((and (or (eq (car a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503 (and (eq (car a) '/) origin))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
504 (Math-realp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
505 (let ((s (if (eq (car a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506 (if (Math-zerop (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (math-possible-signs 0 origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
508 (math-possible-signs (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
509 (math-div (or origin 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 (math-neg-signs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
512 (math-possible-signs (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (math-div (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
514 origin))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515 (if (Math-negp (nth 1 a)) (math-neg-signs s) s)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516 ((and (memq (car a) '(* /)) (Math-realp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 (let ((s (math-possible-signs (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518 (if (eq (car a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (math-mul (or origin 0) (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
520 (math-div (or origin 0) (nth 2 a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
521 (if (Math-negp (nth 2 a)) (math-neg-signs s) s)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 ((eq (car a) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (let ((signs 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 (while (and (setq a (cdr a)) (< signs 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (setq signs (logior signs (math-possible-signs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (car a) origin))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
527 signs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
528 (t (let ((sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 ((memq (car a) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
531 (let ((s1 (math-possible-signs (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (s2 (math-possible-signs (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 (cond ((>= s1 8) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 ((>= s2 8) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 ((and (eq (car a) '/) (memq s2 '(2 3 6 7))) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (logior (if (memq s1 '(4 5 6 7)) s2 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 (if (memq s1 '(2 3 6 7)) 2 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
539 (if (memq s1 '(1 3 5 7))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
540 (math-neg-signs s2) 0))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
541 ((eq (car a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 (let ((s1 (math-possible-signs (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 (s2 (math-possible-signs (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
544 (cond ((>= s1 8) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545 ((>= s2 8) 15)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 ((eq s1 4) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547 ((eq s1 2) (if (eq s2 4) 2 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
548 ((eq s2 2) (if (memq s1 '(1 5)) 2 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
549 ((Math-integerp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
550 (if (math-evenp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
551 (if (memq s1 '(3 6 7)) 6 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
552 s1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
553 ((eq s1 6) (if (eq s2 4) 6 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
554 (t 7))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 ((eq (car a) '%)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
556 (let ((s2 (math-possible-signs (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
557 (cond ((>= s2 8) 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
558 ((eq s2 2) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 ((memq s2 '(4 6)) 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 ((memq s2 '(1 3)) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
561 (t 7))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 ((and (memq (car a) '(calcFunc-abs calcFunc-abssqr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
563 (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 (let ((s1 (math-possible-signs (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565 (cond ((eq s1 2) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 ((memq s1 '(1 4 5)) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (t 6))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
568 ((and (eq (car a) 'calcFunc-exp) (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569 (let ((s1 (math-possible-signs (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
570 (if (>= s1 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
571 15
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572 (if (or (not origin) (math-negp origin))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 4
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
574 (setq origin (math-sub (or origin 0) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (if (Math-zerop origin) (setq origin nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 s1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 ((or (and (memq (car a) '(calcFunc-ln calcFunc-log10))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
579 (and (eq (car a) 'calcFunc-log)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580 (= (length a) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (math-known-posp (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
582 (if (math-known-nonnegp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
583 (math-possible-signs (nth 1 a) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
584 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
585 ((and (eq (car a) 'calcFunc-sqrt) (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586 (let ((s1 (math-possible-signs (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
587 (if (memq s1 '(2 4 6)) s1 15)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
588 ((memq (car a) math-nonnegative-functions) 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589 ((memq (car a) math-positive-functions) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 ((memq (car a) math-real-functions) 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 ((memq (car a) math-real-scalar-functions) 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
592 ((and (memq (car a) math-real-if-arg-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
594 (if (math-known-realp (nth 1 a)) 7 15)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 (cond (sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
596 (if origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
597 (+ (logand sign 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
598 (if (Math-posp origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599 (if (memq sign '(1 2 3 8 9 10 11)) 1 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 (if (memq sign '(2 4 6 8 10 12 14)) 4 7)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 sign))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602 ((math-const-var a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 (cond ((eq (nth 2 a) 'var-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
604 (if origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
605 (math-possible-signs (math-pi) origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607 ((eq (nth 2 a) 'var-e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
608 (if origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
609 (math-possible-signs (math-e) origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
610 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
611 ((eq (nth 2 a) 'var-inf) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
612 ((eq (nth 2 a) 'var-uinf) 13)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613 ((eq (nth 2 a) 'var-i) 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
614 (t 15)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
615 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
616 (math-setup-declarations)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
617 (let ((decl (if (eq (car a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
618 (or (assq (nth 2 a) math-decls-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
619 math-decls-all)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
620 (assq (car a) math-decls-cache))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
621 (if (and origin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
622 (memq 'int (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
623 (not (Math-num-integerp origin)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
624 5
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
625 (if (nth 2 decl)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
626 (math-possible-signs (nth 2 decl) origin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627 (if (memq 'real (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 7
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
629 15))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 (defun math-neg-signs (s1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
632 (if (>= s1 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
633 (+ 8 (math-neg-signs (- s1 8)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
634 (+ (if (memq s1 '(1 3 5 7)) 4 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 (if (memq s1 '(2 3 6 7)) 2 0)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
636 (if (memq s1 '(4 5 6 7)) 1 0))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 ;;; Try to prove that A is an integer.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 (defun math-known-integerp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
641 (eq (math-possible-types a) 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 (defun math-known-num-integerp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
644 (<= (math-possible-types a t) 3))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
645
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
646 (defun math-known-imagp (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
647 (= (math-possible-types a) 16))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
650 ;;; Find the possible types of A.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 ;;; Returns an integer with bits: 1 may be integer.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
652 ;;; 2 may be integer-valued float.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
653 ;;; 4 may be fraction.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
654 ;;; 8 may be non-integer-valued float.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
655 ;;; 16 may be imaginary.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
656 ;;; 32 may be non-real, non-imaginary.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
657 ;;; Real infinities count as integers for the purposes of this function.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
658 (defun math-possible-types (a &optional num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 (cond ((Math-objectp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
660 (cond ((Math-integerp a) (if num 3 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 ((Math-messy-integerp a) (if num 3 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 ((eq (car a) 'frac) (if num 12 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 ((eq (car a) 'float) (if num 12 8))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (if (equal (nth 2 a) (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
666 (math-possible-types (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
667 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
668 ((eq (car a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
669 (if (math-known-realp (nth 1 a)) 15 63))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670 ((eq (car a) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
671 (if (math-zerop (nth 1 a)) 16 32))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 ((eq (car a) 'polar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
673 (if (or (Math-equal (nth 2 a) (math-quarter-circle nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
674 (Math-equal (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
675 (math-neg (math-quarter-circle nil))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
676 16 48))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 (t 63)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
678 ((eq (car a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679 (let* ((t1 (math-possible-types (nth 1 a) num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 (t2 (math-possible-types (nth 2 a) num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 (t12 (logior t1 t2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 (if (< t12 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 (if (> (logand t12 10) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
684 10
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
685 (if (or (= t1 4) (= t2 4) calc-prefer-frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
686 5
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
687 15))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (if (< t12 32)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (if (= t1 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
690 (if (= t2 16) 15
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
691 (if (< t2 16) 16 31))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
692 (if (= t2 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
693 (if (< t1 16) 16 31)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
694 31))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
695 63))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
696 ((memq (car a) '(+ - * %))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
697 (let* ((t1 (math-possible-types (nth 1 a) num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (t2 (math-possible-types (nth 2 a) num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (t12 (logior t1 t2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (if (eq (car a) '%)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
701 (setq t1 (logand t1 15) t2 (logand t2 15) t12 (logand t12 15)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
702 (if (< t12 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (let ((mask (if (<= t12 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
705 (if (and (or (and (<= t1 3) (= (logand t2 3) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
706 (and (<= t2 3) (= (logand t1 3) 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
707 (memq (car a) '(+ -)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
708 4
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 5))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
710 (if num
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711 (* mask 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
712 (logior (if (and (> (logand t1 5) 0) (> (logand t2 5) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
713 mask 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
714 (if (> (logand t12 10) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
715 (* mask 2) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
716 (if (< t12 32)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
717 (if (eq (car a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
718 (if (= t1 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
719 (if (= t2 16) 15
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
720 (if (< t2 16) 16 31))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
721 (if (= t2 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
722 (if (< t1 16) 16 31)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
723 31))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
724 (if (= t12 16) 16
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725 (if (or (and (= t1 16) (< t2 16))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
726 (and (= t2 16) (< t1 16))) 32 63)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
727 63))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
728 ((eq (car a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
729 (math-possible-types (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
730 ((eq (car a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
731 (let* ((t1 (math-possible-types (nth 1 a) num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
732 (t2 (math-possible-types (nth 2 a) num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
733 (t12 (logior t1 t2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
734 (if (and (<= t2 3) (math-known-nonnegp (nth 2 a)) (< t1 16))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
735 (let ((mask (logior (if (> (logand t1 3) 0) 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
736 (logand t1 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
737 (if (> (logand t1 12) 0) 5 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
738 (if num
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
739 (* mask 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
740 (logior (if (and (> (logand t1 5) 0) (> (logand t2 5) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
741 mask 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
742 (if (> (logand t12 10) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
743 (* mask 2) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
744 (if (and (math-known-nonnegp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
745 (math-known-posp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
746 15
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
747 63))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
748 ((eq (car a) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
749 (let ((t1 (math-possible-signs (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
750 (logior (if (> (logand t1 2) 0) 3 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
751 (if (> (logand t1 1) 0) 16 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
752 (if (> (logand t1 4) 0) 15 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
753 (if (> (logand t1 8) 0) 32 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
754 ((eq (car a) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
755 (let ((types 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
756 (while (and (setq a (cdr a)) (< types 63))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
757 (setq types (logior types (math-possible-types (car a) t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
758 types))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
759 ((or (memq (car a) math-integer-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
760 (and (memq (car a) math-rounding-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
761 (math-known-nonnegp (or (nth 2 a) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
762 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
763 ((or (memq (car a) math-num-integer-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
764 (and (memq (car a) math-float-rounding-functions)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
765 (math-known-nonnegp (or (nth 2 a) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
766 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
767 ((eq (car a) 'calcFunc-frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
768 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
769 ((and (eq (car a) 'calcFunc-float) (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
770 (let ((t1 (math-possible-types (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
771 (logior (if (> (logand t1 3) 0) 2 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
772 (if (> (logand t1 12) 0) 8 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
773 (logand t1 48))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
774 ((and (memq (car a) '(calcFunc-abs calcFunc-abssqr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
775 (= (length a) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
776 (let ((t1 (math-possible-types (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
777 (if (>= t1 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
778 15
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
779 t1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
780 ((math-const-var a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
781 (cond ((memq (nth 2 a) '(var-e var-pi var-phi var-gamma)) 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
782 ((eq (nth 2 a) 'var-inf) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
783 ((eq (nth 2 a) 'var-i) 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
784 (t 63)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
785 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
786 (math-setup-declarations)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
787 (let ((decl (if (eq (car a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
788 (or (assq (nth 2 a) math-decls-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
789 math-decls-all)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
790 (assq (car a) math-decls-cache))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
791 (cond ((memq 'int (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
792 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
793 ((memq 'numint (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
794 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
795 ((memq 'frac (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
796 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
797 ((memq 'rat (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
798 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
799 ((memq 'float (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
800 10)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
801 ((nth 2 decl)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802 (math-possible-types (nth 2 decl)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
803 ((memq 'real (nth 1 decl))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
804 15)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
805 (t 63))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
806
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
807 (defun math-known-evenp (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
808 (cond ((Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
809 (math-evenp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
810 ((Math-messy-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
811 (or (> (nth 2 a) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
812 (math-evenp (math-trunc a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
813 ((eq (car a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
814 (if (math-known-evenp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
815 (math-known-num-integerp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
816 (if (math-known-num-integerp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
817 (math-known-evenp (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
818 ((memq (car a) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
819 (or (and (math-known-evenp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
820 (math-known-evenp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
821 (and (math-known-oddp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
822 (math-known-oddp (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
823 ((eq (car a) 'neg)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
824 (math-known-evenp (nth 1 a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
825
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
826 (defun math-known-oddp (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
827 (cond ((Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
828 (math-oddp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
829 ((Math-messy-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
830 (and (<= (nth 2 a) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
831 (math-oddp (math-trunc a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
832 ((memq (car a) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
833 (or (and (math-known-evenp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
834 (math-known-oddp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
835 (and (math-known-oddp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
836 (math-known-evenp (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
837 ((eq (car a) 'neg)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
838 (math-known-oddp (nth 1 a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
839
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
840
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
841 (defun calcFunc-dreal (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
842 (let ((types (math-possible-types expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
843 (if (< types 16) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
844 (if (= (logand types 15) 0) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
845 (math-reject-arg expr 'realp 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
846
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
847 (defun calcFunc-dimag (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
848 (let ((types (math-possible-types expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
849 (if (= types 16) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
850 (if (= (logand types 16) 0) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
851 (math-reject-arg expr "Expected an imaginary number")))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
852
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
853 (defun calcFunc-dpos (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
854 (let ((signs (math-possible-signs expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
855 (if (eq signs 4) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
856 (if (memq signs '(1 2 3)) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
857 (math-reject-arg expr 'posp 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
858
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
859 (defun calcFunc-dneg (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
860 (let ((signs (math-possible-signs expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
861 (if (eq signs 1) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
862 (if (memq signs '(2 4 6)) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
863 (math-reject-arg expr 'negp 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
864
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
865 (defun calcFunc-dnonneg (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
866 (let ((signs (math-possible-signs expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
867 (if (memq signs '(2 4 6)) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
868 (if (eq signs 1) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
869 (math-reject-arg expr 'posp 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
870
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
871 (defun calcFunc-dnonzero (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
872 (let ((signs (math-possible-signs expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
873 (if (memq signs '(1 4 5 8 9 12 13)) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
874 (if (eq signs 2) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
875 (math-reject-arg expr 'nonzerop 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
876
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
877 (defun calcFunc-dint (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
878 (let ((types (math-possible-types expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
879 (if (= types 1) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
880 (if (= (logand types 1) 0) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
881 (math-reject-arg expr 'integerp 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
882
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
883 (defun calcFunc-dnumint (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
884 (let ((types (math-possible-types expr t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
885 (if (<= types 3) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
886 (if (= (logand types 3) 0) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
887 (math-reject-arg expr 'integerp 'quiet)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
888
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
889 (defun calcFunc-dnatnum (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
890 (let ((res (calcFunc-dint expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
891 (if (eq res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
892 (calcFunc-dnonneg expr)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
893 res)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
894
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
895 (defun calcFunc-deven (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
896 (if (math-known-evenp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
897 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
898 (if (or (math-known-oddp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
899 (= (logand (math-possible-types expr) 3) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
900 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
901 (math-reject-arg expr "Can't tell if expression is odd or even"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
902
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
903 (defun calcFunc-dodd (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
904 (if (math-known-oddp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
905 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
906 (if (or (math-known-evenp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
907 (= (logand (math-possible-types expr) 3) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
908 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
909 (math-reject-arg expr "Can't tell if expression is odd or even"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
910
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
911 (defun calcFunc-drat (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
912 (let ((types (math-possible-types expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
913 (if (memq types '(1 4 5)) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
914 (if (= (logand types 5) 0) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
915 (math-reject-arg expr "Rational number expected")))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
916
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
917 (defun calcFunc-drange (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
918 (math-setup-declarations)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
919 (let (range)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
920 (if (Math-realp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
921 (list 'vec expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
922 (if (eq (car-safe expr) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
923 expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
924 (if (eq (car-safe expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
925 (setq range (nth 2 (or (assq (nth 2 expr) math-decls-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
926 math-decls-all)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
927 (setq range (nth 2 (assq (car-safe expr) math-decls-cache))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
928 (if range
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
929 (math-clean-set (copy-sequence range))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
930 (setq range (math-possible-signs expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
931 (if (< range 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
932 (aref [(vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
933 (intv 2 (neg (var inf var-inf)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
934 (vec 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
935 (intv 3 (neg (var inf var-inf)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
936 (intv 1 0 (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
937 (vec (intv 2 (neg (var inf var-inf)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
938 (intv 1 0 (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
939 (intv 3 0 (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
940 (intv 3 (neg (var inf var-inf)) (var inf var-inf))] range)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
941 (math-reject-arg expr 'realp 'quiet)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
942
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
943 (defun calcFunc-dscalar (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
944 (if (math-known-scalarp a) 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
945 (if (math-known-matrixp a) 0
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
946 (math-reject-arg a 'objectp 'quiet))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
947
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
948
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
949 ;;;; Arithmetic.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
950
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
951 (defsubst calcFunc-neg (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
952 (math-normalize (list 'neg a)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
953
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
954 (defun math-neg-fancy (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
955 (cond ((eq (car a) 'polar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
956 (list 'polar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
957 (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
958 (if (math-posp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
959 (math-sub (nth 2 a) (math-half-circle nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
960 (math-add (nth 2 a) (math-half-circle nil)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
961 ((eq (car a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
962 (if (math-zerop (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
963 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
964 (list 'mod (math-sub (nth 2 a) (nth 1 a)) (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
965 ((eq (car a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
966 (list 'sdev (math-neg (nth 1 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
967 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
968 (math-make-intv (aref [0 2 1 3] (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
969 (math-neg (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
970 (math-neg (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
971 ((and math-simplify-only
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
972 (not (equal a math-simplify-only)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
973 (list 'neg a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
974 ((eq (car a) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
975 (math-sub (math-neg (nth 1 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
976 ((eq (car a) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
977 (math-sub (nth 2 a) (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
978 ((and (memq (car a) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
979 (math-okay-neg (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
980 (list (car a) (math-neg (nth 1 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
981 ((and (memq (car a) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
982 (math-okay-neg (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
983 (list (car a) (nth 1 a) (math-neg (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
984 ((and (memq (car a) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
985 (or (math-objectp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
986 (and (eq (car (nth 1 a)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
987 (math-objectp (nth 1 (nth 1 a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
988 (list (car a) (math-neg (nth 1 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
989 ((and (eq (car a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
990 (or (math-objectp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
991 (and (eq (car (nth 2 a)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
992 (math-objectp (nth 1 (nth 2 a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
993 (list (car a) (nth 1 a) (math-neg (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
994 ((and (eq (car a) 'var) (memq (nth 2 a) '(var-uinf var-nan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
995 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
996 ((eq (car a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
997 (nth 1 a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
998 (t (list 'neg a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
999
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1000 (defun math-okay-neg (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1001 (or (math-looks-negp a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1002 (eq (car-safe a) '-)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1003
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1004 (defun math-neg-float (a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1005 (list 'float (Math-integer-neg (nth 1 a)) (nth 2 a)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1006
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1007
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1008 (defun calcFunc-add (&rest rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1009 (if rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1010 (let ((a (car rest)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1011 (while (setq rest (cdr rest))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1012 (setq a (list '+ a (car rest))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1013 (math-normalize a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1014 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1015
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1016 (defun calcFunc-sub (&rest rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1017 (if rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1018 (let ((a (car rest)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1019 (while (setq rest (cdr rest))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1020 (setq a (list '- a (car rest))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1021 (math-normalize a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1022 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1023
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1024 (defun math-add-objects-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1025 (cond ((and (Math-numberp a) (Math-numberp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1026 (let ((aa (math-complex a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1027 (bb (math-complex b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1028 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1029 (let ((res (list 'cplx
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1030 (math-add (nth 1 aa) (nth 1 bb))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1031 (math-add (nth 2 aa) (nth 2 bb)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1032 (if (math-want-polar a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1033 (math-polar res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1034 res)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1035 ((or (Math-vectorp a) (Math-vectorp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1036 (math-map-vec-2 'math-add a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1037 ((eq (car-safe a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1038 (if (eq (car-safe b) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1039 (math-make-sdev (math-add (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1040 (math-hypot (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1041 (and (or (Math-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1042 (not (Math-objvecp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1043 (math-make-sdev (math-add (nth 1 a) b) (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1044 ((and (eq (car-safe b) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1045 (or (Math-scalarp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1046 (not (Math-objvecp a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1047 (math-make-sdev (math-add a (nth 1 b)) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1048 ((eq (car-safe a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1049 (if (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1050 (math-make-intv (logior (logand (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1051 (if (equal (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1052 '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1053 (logand (nth 1 a) 2) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1054 (if (equal (nth 2 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1055 '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1056 (logand (nth 1 b) 2) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1057 (if (equal (nth 3 a) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1058 (logand (nth 1 a) 1) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1059 (if (equal (nth 3 b) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1060 (logand (nth 1 b) 1) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1061 (math-add (nth 2 a) (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1062 (math-add (nth 3 a) (nth 3 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1063 (and (or (Math-anglep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1064 (eq (car b) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1065 (not (Math-objvecp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1066 (math-make-intv (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1067 (math-add (nth 2 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1068 (math-add (nth 3 a) b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1069 ((and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1070 (or (Math-anglep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1071 (eq (car a) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1072 (not (Math-objvecp a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1073 (math-make-intv (nth 1 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1074 (math-add a (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1075 (math-add a (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1076 ((eq (car-safe a) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1077 (cond ((eq (car-safe b) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1078 (math-add (nth 1 a) (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1079 ((eq (car-safe b) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1080 (let ((parts (math-date-parts (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1081 (list 'date
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1082 (math-add (car parts) ; this minimizes roundoff
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1083 (math-div (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1084 (math-add (nth 1 parts)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1085 (nth 2 parts))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1086 (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1087 (math-mul (nth 1 b) 3600)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1088 (math-add (math-mul (nth 2 b) 60)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1089 (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1090 86400)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1091 ((Math-realp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1092 (list 'date (math-add (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1093 (t nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1094 ((eq (car-safe b) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1095 (math-add-objects-fancy b a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1096 ((and (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1097 (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1098 (equal (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1099 (math-make-mod (math-add (nth 1 a) (nth 1 b)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1100 ((and (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1101 (Math-anglep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1102 (math-make-mod (math-add (nth 1 a) b) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1103 ((and (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1104 (Math-anglep a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1105 (math-make-mod (math-add a (nth 1 b)) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1106 ((and (or (eq (car-safe a) 'hms) (eq (car-safe b) 'hms))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1107 (and (Math-anglep a) (Math-anglep b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1108 (or (eq (car-safe a) 'hms) (setq a (math-to-hms a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1109 (or (eq (car-safe b) 'hms) (setq b (math-to-hms b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1110 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1111 (if (math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1112 (math-neg (math-add (math-neg a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1113 (if (math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1114 (let* ((s (math-add (nth 3 a) (nth 3 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1115 (m (math-add (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1116 (h (math-add (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1117 (if (math-negp s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1118 (setq s (math-add s 60)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1119 m (math-add m -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1120 (if (math-negp m)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1121 (setq m (math-add m 60)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1122 h (math-add h -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1123 (if (math-negp h)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1124 (math-add b a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1125 (list 'hms h m s)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1126 (let* ((s (math-add (nth 3 a) (nth 3 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1127 (m (math-add (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1128 (h (math-add (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1129 (list 'hms h m s))))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1130 (t (calc-record-why "*Incompatible arguments for +" a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1131
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1132 (defun math-add-symb-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1133 (or (and math-simplify-only
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1134 (not (equal a math-simplify-only))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1135 (list '+ a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1136 (and (eq (car-safe b) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1137 (math-add (math-add a (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1138 (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1139 (and (eq (car-safe b) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1140 (math-sub (math-add a (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1141 (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1142 (and (eq (car-safe b) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1143 (eq (car-safe (nth 1 b)) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1144 (math-sub (math-sub a (nth 1 (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1145 (nth 2 (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1146 (and (or (and (Math-vectorp a) (math-known-scalarp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1147 (and (Math-vectorp b) (math-known-scalarp a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1148 (math-map-vec-2 'math-add a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1149 (let ((inf (math-infinitep a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1150 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1151 (inf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1152 (let ((inf2 (math-infinitep b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1153 (if inf2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1154 (if (or (memq (nth 2 inf) '(var-uinf var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1155 (memq (nth 2 inf2) '(var-uinf var-nan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1156 '(var nan var-nan)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1157 (let ((dir (math-infinite-dir a inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1158 (dir2 (math-infinite-dir b inf2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1159 (if (and (Math-objectp dir) (Math-objectp dir2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1160 (if (Math-equal dir dir2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1161 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1162 '(var nan var-nan)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1163 (if (and (equal a '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1164 (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1165 (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1166 (equal (nth 2 b) '(neg (var inf var-inf))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1167 (list 'intv 3 (nth 2 b) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1168 (if (and (equal a '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1169 (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1170 (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1171 (equal (nth 3 b) '(var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1172 (list 'intv 3 a (nth 3 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1173 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1174 ((math-infinitep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1175 (if (eq (car-safe a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1176 (math-add b a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1177 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1178 ((eq (car-safe a) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1179 (let ((temp (math-combine-sum (nth 2 a) b nil nil t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1180 (and temp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1181 (math-add (nth 1 a) temp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1182 ((eq (car-safe a) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1183 (let ((temp (math-combine-sum (nth 2 a) b t nil t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1184 (and temp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1185 (math-add (nth 1 a) temp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1186 ((and (Math-objectp a) (Math-objectp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1187 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1188 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1189 (math-combine-sum a b nil nil nil))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1190 (and (Math-looks-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1191 (list '- a (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1192 (and (Math-looks-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1193 (list '- b (math-neg a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1194 (and (eq (car-safe a) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1195 (= (length a) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1196 (or (and (eq (car-safe b) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1197 (= (length b) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1198 (list 'calcFunc-idn (math-add (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1199 (and (math-square-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1200 (math-add (math-mimic-ident (nth 1 a) b) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1201 (and (math-known-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1202 (math-add (nth 1 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1203 (and (eq (car-safe b) 'calcFunc-idn)
68306
1da5034b091b (math-add-symb-fancy): Check the length of the correct variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66866
diff changeset
1204 (= (length b) 2)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1205 (or (and (math-square-matrixp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1206 (math-add a (math-mimic-ident (nth 1 b) a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1207 (and (math-known-scalarp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1208 (math-add a (nth 1 b)))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1209 (list '+ a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1210
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1211
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1212 (defun calcFunc-mul (&rest rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1213 (if rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1214 (let ((a (car rest)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1215 (while (setq rest (cdr rest))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1216 (setq a (list '* a (car rest))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1217 (math-normalize a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1218 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1219
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1220 (defun math-mul-objects-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1221 (cond ((and (Math-numberp a) (Math-numberp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1222 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1223 (if (math-want-polar a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1224 (let ((a (math-polar a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1225 (b (math-polar b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1226 (list 'polar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1227 (math-mul (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1228 (math-fix-circular (math-add (nth 2 a) (nth 2 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1229 (setq a (math-complex a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1230 b (math-complex b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1231 (list 'cplx
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1232 (math-sub (math-mul (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1233 (math-mul (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1234 (math-add (math-mul (nth 1 a) (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1235 (math-mul (nth 2 a) (nth 1 b)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1236 ((Math-vectorp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1237 (if (Math-vectorp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1238 (if (math-matrixp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1239 (if (math-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1240 (if (= (length (nth 1 a)) (length b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1241 (math-mul-mats a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1242 (math-dimension-error))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1243 (if (= (length (nth 1 a)) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1244 (if (= (length a) (length b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1245 (math-mul-mats a (list 'vec b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1246 (math-dimension-error))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1247 (if (= (length (nth 1 a)) (length b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1248 (math-mul-mat-vec a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1249 (math-dimension-error))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1250 (if (math-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1251 (if (= (length a) (length b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1252 (nth 1 (math-mul-mats (list 'vec a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1253 (math-dimension-error))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1254 (if (= (length a) (length b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1255 (math-dot-product a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1256 (math-dimension-error))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1257 (math-map-vec-2 'math-mul a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1258 ((Math-vectorp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1259 (math-map-vec-2 'math-mul a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1260 ((eq (car-safe a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1261 (if (eq (car-safe b) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1262 (math-make-sdev (math-mul (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1263 (math-hypot (math-mul (nth 2 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1264 (math-mul (nth 2 b) (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1265 (and (or (Math-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1266 (not (Math-objvecp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1267 (math-make-sdev (math-mul (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1268 (math-mul (nth 2 a) b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1269 ((and (eq (car-safe b) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1270 (or (Math-scalarp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1271 (not (Math-objvecp a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1272 (math-make-sdev (math-mul a (nth 1 b)) (math-mul a (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1273 ((and (eq (car-safe a) 'intv) (Math-anglep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1274 (if (Math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1275 (math-neg (math-mul a (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1276 (math-make-intv (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1277 (math-mul (nth 2 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1278 (math-mul (nth 3 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1279 ((and (eq (car-safe b) 'intv) (Math-anglep a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1280 (math-mul b a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1281 ((and (eq (car-safe a) 'intv) (math-intv-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1282 (eq (car-safe b) 'intv) (math-intv-constp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1283 (let ((lo (math-mul a (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1284 (hi (math-mul a (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1285 (or (eq (car-safe lo) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1286 (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0) lo lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1287 (or (eq (car-safe hi) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1288 (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0) hi hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1289 (math-combine-intervals
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1290 (nth 2 lo) (and (or (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1291 (math-infinitep (nth 2 lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1292 (memq (nth 1 lo) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1293 (nth 3 lo) (and (or (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1294 (math-infinitep (nth 3 lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1295 (memq (nth 1 lo) '(1 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1296 (nth 2 hi) (and (or (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1297 (math-infinitep (nth 2 hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1298 (memq (nth 1 hi) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1299 (nth 3 hi) (and (or (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1300 (math-infinitep (nth 3 hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1301 (memq (nth 1 hi) '(1 3))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1302 ((and (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1303 (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1304 (equal (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1305 (math-make-mod (math-mul (nth 1 a) (nth 1 b)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1306 ((and (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1307 (Math-anglep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1308 (math-make-mod (math-mul (nth 1 a) b) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1309 ((and (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1310 (Math-anglep a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1311 (math-make-mod (math-mul a (nth 1 b)) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1312 ((and (eq (car-safe a) 'hms) (Math-realp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1313 (math-with-extra-prec 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1314 (math-to-hms (math-mul (math-from-hms a 'deg) b) 'deg)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1315 ((and (eq (car-safe b) 'hms) (Math-realp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1316 (math-mul b a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1317 (t (calc-record-why "*Incompatible arguments for *" a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1318
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1319 ;;; Fast function to multiply floating-point numbers.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1320 (defun math-mul-float (a b) ; [F F F]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1321 (math-make-float (math-mul (nth 1 a) (nth 1 b))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1322 (+ (nth 2 a) (nth 2 b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1323
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1324 (defun math-sqr-float (a) ; [F F]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1325 (math-make-float (math-mul (nth 1 a) (nth 1 a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1326 (+ (nth 2 a) (nth 2 a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1327
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1328 (defun math-intv-constp (a &optional finite)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1329 (and (or (Math-anglep (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1330 (and (equal (nth 2 a) '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1331 (or (not finite)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1332 (memq (nth 1 a) '(0 1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1333 (or (Math-anglep (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1334 (and (equal (nth 3 a) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1335 (or (not finite)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1336 (memq (nth 1 a) '(0 2)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1337
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1338 (defun math-mul-zero (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1339 (if (math-known-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1340 (if (math-vectorp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1341 (math-map-vec-2 'math-mul a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1342 (math-mimic-ident 0 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1343 (if (math-infinitep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1344 '(var nan var-nan)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1345 (let ((aa nil) (bb nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1346 (if (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1347 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1348 (and (equal (nth 2 b) '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1349 (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1350 (setq aa (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1351 (and (equal (nth 3 b) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1352 (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1353 (setq bb (nth 3 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1354 (or aa bb)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1355 (if (or (math-posp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1356 (and (math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1357 (or (memq calc-infinite-mode '(-1 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1358 (setq aa '(neg (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1359 bb '(var inf var-inf)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1360 (list 'intv 3 (or aa 0) (or bb 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1361 (if (math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1362 (math-neg (list 'intv 3 (or aa 0) (or bb 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1363 '(var nan var-nan)))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1364 (if (or (math-floatp a) (math-floatp b)) '(float 0 0) 0))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1365
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1366
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1367 (defun math-mul-symb-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1368 (or (and math-simplify-only
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1369 (not (equal a math-simplify-only))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1370 (list '* a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1371 (and (Math-equal-int a 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1372 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1373 (and (Math-equal-int a -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1374 (math-neg b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1375 (and (or (and (Math-vectorp a) (math-known-scalarp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1376 (and (Math-vectorp b) (math-known-scalarp a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1377 (math-map-vec-2 'math-mul a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1378 (and (Math-objectp b) (not (Math-objectp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1379 (math-mul b a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1380 (and (eq (car-safe a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1381 (math-neg (math-mul (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1382 (and (eq (car-safe b) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1383 (math-neg (math-mul a (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1384 (and (eq (car-safe a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1385 (math-mul (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1386 (math-mul (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1387 (and (eq (car-safe a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1388 (Math-looks-negp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1389 (not (and (eq (car-safe b) '^) (Math-looks-negp (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1390 (math-known-scalarp b t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1391 (math-div b (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1392 (list '^ (nth 1 a) (math-neg (nth 2 a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1393 (and (eq (car-safe b) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1394 (Math-looks-negp (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1395 (not (and (eq (car-safe a) '^) (Math-looks-negp (nth 2 a))))
66479
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1396 (not (math-known-matrixp (nth 1 b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1397 (math-div a (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1398 (list '^ (nth 1 b) (math-neg (nth 2 b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1399 (and (eq (car-safe a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1400 (or (math-known-scalarp a t) (math-known-scalarp b t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1401 (let ((temp (math-combine-prod (nth 2 a) b t nil t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1402 (if temp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1403 (math-mul (nth 1 a) temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1404 (math-div (math-mul (nth 1 a) b) (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1405 (and (eq (car-safe b) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1406 (math-div (math-mul a (nth 1 b)) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1407 (and (eq (car-safe b) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1408 (Math-numberp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1409 (or (Math-numberp (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1410 (Math-numberp (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1411 (math-add (math-mul a (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1412 (math-mul a (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1413 (and (eq (car-safe b) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1414 (Math-numberp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1415 (or (Math-numberp (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1416 (Math-numberp (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1417 (math-sub (math-mul a (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1418 (math-mul a (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1419 (and (eq (car-safe b) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1420 (Math-numberp (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1421 (not (Math-numberp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1422 (math-mul (nth 1 b) (math-mul a (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1423 (and (eq (car-safe a) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1424 (= (length a) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1425 (or (and (eq (car-safe b) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1426 (= (length b) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1427 (list 'calcFunc-idn (math-mul (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1428 (and (math-known-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1429 (list 'calcFunc-idn (math-mul (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1430 (and (math-known-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1431 (math-mul (nth 1 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1432 (and (eq (car-safe b) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1433 (= (length b) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1434 (or (and (math-known-scalarp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1435 (list 'calcFunc-idn (math-mul a (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1436 (and (math-known-matrixp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1437 (math-mul a (nth 1 b)))))
66479
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1438 (and (math-identity-matrix-p a t)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1439 (or (and (eq (car-safe b) 'calcFunc-idn)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1440 (= (length b) 2)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1441 (list 'calcFunc-idn (math-mul
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1442 (nth 1 (nth 1 a))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1443 (nth 1 b))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1444 (1- (length a))))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1445 (and (math-known-scalarp b)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1446 (list 'calcFunc-idn (math-mul
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1447 (nth 1 (nth 1 a)) b)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1448 (1- (length a))))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1449 (and (math-known-matrixp b)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1450 (math-mul (nth 1 (nth 1 a)) b))))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1451 (and (math-identity-matrix-p b t)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1452 (or (and (eq (car-safe a) 'calcFunc-idn)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1453 (= (length a) 2)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1454 (list 'calcFunc-idn (math-mul (nth 1 a)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1455 (nth 1 (nth 1 b)))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1456 (1- (length b))))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1457 (and (math-known-scalarp a)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1458 (list 'calcFunc-idn (math-mul a (nth 1 (nth 1 b)))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1459 (1- (length b))))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1460 (and (math-known-matrixp a)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1461 (math-mul a (nth 1 (nth 1 b))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1462 (and (math-looks-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1463 (math-mul (math-neg a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1464 (and (eq (car-safe b) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1465 (math-looks-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1466 (math-mul (math-neg a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1467 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1468 ((eq (car-safe b) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1469 (let ((temp (math-combine-prod a (nth 1 b) nil nil t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1470 (and temp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1471 (math-mul temp (nth 2 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1472 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1473 (math-combine-prod a b nil nil nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1474 (and (equal a '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1475 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1476 (and (equal b '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1477 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1478 (and (equal a '(var uinf var-uinf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1479 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1480 (and (equal b '(var uinf var-uinf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1481 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1482 (and (equal b '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1483 (let ((s1 (math-possible-signs a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1484 (cond ((eq s1 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1485 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1486 ((eq s1 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1487 '(intv 3 0 (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1488 ((eq s1 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1489 (math-neg b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1490 ((eq s1 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1491 '(intv 3 (neg (var inf var-inf)) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1492 ((and (eq (car a) 'intv) (math-intv-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1493 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1494 ((and (eq (car a) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1495 (math-zerop (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1496 (list '* (list 'cplx 0 (calcFunc-sign (nth 2 a))) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1497 ((eq (car a) 'polar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1498 (list '* (list 'polar 1 (nth 2 a)) b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1499 (and (equal a '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1500 (math-mul b a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1501 (list '* a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1502
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1503
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1504 (defun calcFunc-div (a &rest rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1505 (while rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1506 (setq a (list '/ a (car rest))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1507 rest (cdr rest)))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1508 (math-normalize a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1509
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1510 (defun math-div-objects-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1511 (cond ((and (Math-numberp a) (Math-numberp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1512 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1513 (cond ((math-want-polar a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1514 (let ((a (math-polar a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1515 (b (math-polar b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1516 (list 'polar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1517 (math-div (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1518 (math-fix-circular (math-sub (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1519 (nth 2 b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1520 ((Math-realp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1521 (setq a (math-complex a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1522 (list 'cplx (math-div (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1523 (math-div (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1524 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1525 (setq a (math-complex a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1526 b (math-complex b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1527 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1528 (list 'cplx
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1529 (math-add (math-mul (nth 1 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1530 (math-mul (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1531 (math-sub (math-mul (nth 2 a) (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1532 (math-mul (nth 1 a) (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1533 (math-add (math-sqr (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1534 (math-sqr (nth 2 b))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1535 ((math-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1536 (if (math-square-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1537 (let ((n1 (length b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1538 (if (Math-vectorp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1539 (if (math-matrixp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1540 (if (= (length a) n1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1541 (math-lud-solve (math-matrix-lud b) a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1542 (if (= (length (nth 1 a)) n1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1543 (math-transpose
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1544 (math-lud-solve (math-matrix-lud
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1545 (math-transpose b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1546 (math-transpose a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1547 (math-dimension-error)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1548 (if (= (length a) n1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1549 (math-mat-col (math-lud-solve (math-matrix-lud b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1550 (math-col-matrix a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1551 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1552 (math-dimension-error)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1553 (if (Math-equal-int a 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1554 (calcFunc-inv b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1555 (math-mul a (calcFunc-inv b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1556 (math-reject-arg b 'square-matrixp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1557 ((and (Math-vectorp a) (Math-objectp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1558 (math-map-vec-2 'math-div a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1559 ((eq (car-safe a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1560 (if (eq (car-safe b) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1561 (let ((x (math-div (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1562 (math-make-sdev x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1563 (math-div (math-hypot (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1564 (math-mul (nth 2 b) x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1565 (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1566 (if (or (Math-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1567 (not (Math-objvecp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1568 (math-make-sdev (math-div (nth 1 a) b) (math-div (nth 2 a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1569 (math-reject-arg 'realp b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1570 ((and (eq (car-safe b) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1571 (or (Math-scalarp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1572 (not (Math-objvecp a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1573 (let ((x (math-div a (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1574 (math-make-sdev x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1575 (math-div (math-mul (nth 2 b) x) (nth 1 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1576 ((and (eq (car-safe a) 'intv) (Math-anglep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1577 (if (Math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1578 (math-neg (math-div a (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1579 (math-make-intv (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1580 (math-div (nth 2 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1581 (math-div (nth 3 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1582 ((and (eq (car-safe b) 'intv) (Math-anglep a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1583 (if (or (Math-posp (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1584 (and (Math-zerop (nth 2 b)) (or (memq (nth 1 b) '(0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1585 calc-infinite-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1586 (if (Math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1587 (math-neg (math-div (math-neg a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1588 (let ((calc-infinite-mode 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1589 (math-make-intv (aref [0 2 1 3] (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1590 (math-div a (nth 3 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1591 (math-div a (nth 2 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1592 (if (or (Math-negp (nth 3 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1593 (and (Math-zerop (nth 3 b)) (or (memq (nth 1 b) '(0 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1594 calc-infinite-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1595 (math-neg (math-div a (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1596 (if calc-infinite-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1597 '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1598 (math-reject-arg b "*Division by zero")))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1599 ((and (eq (car-safe a) 'intv) (math-intv-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1600 (eq (car-safe b) 'intv) (math-intv-constp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1601 (if (or (Math-posp (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1602 (and (Math-zerop (nth 2 b)) (or (memq (nth 1 b) '(0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1603 calc-infinite-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1604 (let* ((calc-infinite-mode 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1605 (lo (math-div a (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1606 (hi (math-div a (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1607 (or (eq (car-safe lo) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1608 (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1609 lo lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1610 (or (eq (car-safe hi) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1611 (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1612 hi hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1613 (math-combine-intervals
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1614 (nth 2 lo) (and (or (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1615 (and (math-infinitep (nth 2 lo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1616 (not (math-zerop (nth 2 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1617 (memq (nth 1 lo) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1618 (nth 3 lo) (and (or (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1619 (and (math-infinitep (nth 3 lo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1620 (not (math-zerop (nth 2 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1621 (memq (nth 1 lo) '(1 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1622 (nth 2 hi) (and (or (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1623 (and (math-infinitep (nth 2 hi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1624 (not (math-zerop (nth 3 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1625 (memq (nth 1 hi) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1626 (nth 3 hi) (and (or (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1627 (and (math-infinitep (nth 3 hi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1628 (not (math-zerop (nth 3 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1629 (memq (nth 1 hi) '(1 3)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1630 (if (or (Math-negp (nth 3 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1631 (and (Math-zerop (nth 3 b)) (or (memq (nth 1 b) '(0 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1632 calc-infinite-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1633 (math-neg (math-div a (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1634 (if calc-infinite-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1635 '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1636 (math-reject-arg b "*Division by zero")))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1637 ((and (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1638 (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1639 (equal (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1640 (math-make-mod (math-div-mod (nth 1 a) (nth 1 b) (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1641 (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1642 ((and (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1643 (Math-anglep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1644 (math-make-mod (math-div-mod (nth 1 a) b (nth 2 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1645 ((and (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1646 (Math-anglep a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1647 (math-make-mod (math-div-mod a (nth 1 b) (nth 2 b)) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1648 ((eq (car-safe a) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1649 (if (eq (car-safe b) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1650 (math-with-extra-prec 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1651 (math-div (math-from-hms a 'deg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1652 (math-from-hms b 'deg)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1653 (math-with-extra-prec 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1654 (math-to-hms (math-div (math-from-hms a 'deg) b) 'deg))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1655 (t (calc-record-why "*Incompatible arguments for /" a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1656
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1657 (defun math-div-by-zero (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1658 (if (math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1659 (if (or (equal a '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1660 (equal b '(var uinf var-uinf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1661 (memq calc-infinite-mode '(-1 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1662 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1663 '(var uinf var-uinf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1664 (if calc-infinite-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1665 (if (math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1666 '(var nan var-nan)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1667 (if (eq calc-infinite-mode 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1668 (math-mul a '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1669 (if (eq calc-infinite-mode -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1670 (math-mul a '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1671 (if (eq (car-safe a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1672 '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1673 '(var uinf var-uinf)))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1674 (math-reject-arg a "*Division by zero"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1675
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1676 (defun math-div-zero (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1677 (if (math-known-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1678 (if (math-vectorp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1679 (math-map-vec-2 'math-div a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1680 (math-mimic-ident 0 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1681 (if (equal b '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1682 b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1683 (if (and (eq (car-safe b) 'intv) (math-intv-constp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1684 (not (math-posp b)) (not (math-negp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1685 (if calc-infinite-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1686 (list 'intv 3
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1687 (if (and (math-zerop (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1688 (memq calc-infinite-mode '(1 -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1689 (nth 2 b) '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1690 (if (and (math-zerop (nth 3 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1691 (memq calc-infinite-mode '(1 -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1692 (nth 3 b) '(var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1693 (math-reject-arg b "*Division by zero"))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1694 a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1695
60154
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1696 ;; For math-div-symb-fancy
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1697 (defvar math-trig-inverses
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1698 '((calcFunc-sin . calcFunc-csc)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1699 (calcFunc-cos . calcFunc-sec)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1700 (calcFunc-tan . calcFunc-cot)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1701 (calcFunc-sec . calcFunc-cos)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1702 (calcFunc-csc . calcFunc-sin)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1703 (calcFunc-cot . calcFunc-tan)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1704 (calcFunc-sinh . calcFunc-csch)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1705 (calcFunc-cosh . calcFunc-sech)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1706 (calcFunc-tanh . calcFunc-coth)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1707 (calcFunc-sech . calcFunc-cosh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1708 (calcFunc-csch . calcFunc-sinh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1709 (calcFunc-coth . calcFunc-tanh)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1710
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1711 (defvar math-div-trig)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1712 (defvar math-div-non-trig)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1713
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1714 (defun math-div-new-trig (tr)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1715 (if math-div-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1716 (setq math-div-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1717 (list '* tr math-div-trig))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1718 (setq math-div-trig tr)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1719
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1720 (defun math-div-new-non-trig (ntr)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1721 (if math-div-non-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1722 (setq math-div-non-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1723 (list '* ntr math-div-non-trig))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1724 (setq math-div-non-trig ntr)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1725
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1726 (defun math-div-isolate-trig (expr)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1727 (if (eq (car-safe expr) '*)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1728 (progn
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1729 (math-div-isolate-trig-term (nth 1 expr))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1730 (math-div-isolate-trig (nth 2 expr)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1731 (math-div-isolate-trig-term expr)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1732
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1733 (defun math-div-isolate-trig-term (term)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1734 (let ((fn (assoc (car-safe term) math-trig-inverses)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1735 (if fn
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1736 (math-div-new-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1737 (cons (cdr fn) (cdr term)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1738 (math-div-new-non-trig term))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1739
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1740 (defun math-div-symb-fancy (a b)
66479
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1741 (or (and (math-known-matrixp b)
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1742 (math-mul a (math-pow b -1)))
5da715ee89b8 (calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents: 65993
diff changeset
1743 (and math-simplify-only
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1744 (not (equal a math-simplify-only))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1745 (list '/ a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1746 (and (Math-equal-int b 1) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1747 (and (Math-equal-int b -1) (math-neg a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1748 (and (Math-vectorp a) (math-known-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1749 (math-map-vec-2 'math-div a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1750 (and (eq (car-safe b) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1751 (or (Math-looks-negp (nth 2 b)) (Math-equal-int a 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1752 (math-mul a (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1753 (list '^ (nth 1 b) (math-neg (nth 2 b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1754 (and (eq (car-safe a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1755 (math-neg (math-div (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1756 (and (eq (car-safe b) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1757 (math-neg (math-div a (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1758 (and (eq (car-safe a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1759 (math-div (nth 1 a) (math-mul (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1760 (and (eq (car-safe b) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1761 (or (math-known-scalarp (nth 1 b) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1762 (math-known-scalarp (nth 2 b) t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1763 (math-div (math-mul a (nth 2 b)) (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1764 (and (eq (car-safe b) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1765 (math-mul (math-make-frac (nth 2 b) (nth 1 b)) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1766 (and (eq (car-safe a) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1767 (or (Math-numberp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1768 (Math-numberp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1769 (Math-numberp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1770 (math-add (math-div (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1771 (math-div (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1772 (and (eq (car-safe a) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1773 (or (Math-numberp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1774 (Math-numberp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1775 (Math-numberp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1776 (math-sub (math-div (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1777 (math-div (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1778 (and (or (eq (car-safe a) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1779 (math-looks-negp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1780 (math-looks-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1781 (math-div (math-neg a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1782 (and (eq (car-safe b) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1783 (math-looks-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1784 (math-div (math-neg a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1785 (and (eq (car-safe a) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1786 (= (length a) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1787 (or (and (eq (car-safe b) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1788 (= (length b) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1789 (list 'calcFunc-idn (math-div (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1790 (and (math-known-scalarp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1791 (list 'calcFunc-idn (math-div (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1792 (and (math-known-matrixp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1793 (math-div (nth 1 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1794 (and (eq (car-safe b) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1795 (= (length b) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1796 (or (and (math-known-scalarp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1797 (list 'calcFunc-idn (math-div a (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1798 (and (math-known-matrixp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1799 (math-div a (nth 1 b)))))
60154
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1800 (and math-simplifying
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1801 (let ((math-div-trig nil)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1802 (math-div-non-trig nil))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1803 (math-div-isolate-trig b)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1804 (if math-div-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1805 (if math-div-non-trig
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1806 (math-div (math-mul a math-div-trig) math-div-non-trig)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1807 (math-mul a math-div-trig))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
1808 nil)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1809 (if (and calc-matrix-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1810 (or (math-known-matrixp a) (math-known-matrixp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1811 (math-combine-prod a b nil t nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1812 (if (eq (car-safe a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1813 (if (eq (car-safe b) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1814 (let ((c (math-combine-prod (nth 1 a) (nth 1 b) nil t t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1815 (and c
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1816 (math-div (math-mul c (nth 2 a)) (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1817 (let ((c (math-combine-prod (nth 1 a) b nil t t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1818 (and c
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1819 (math-mul c (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1820 (if (eq (car-safe b) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1821 (let ((c (math-combine-prod a (nth 1 b) nil t t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1822 (and c
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1823 (math-div c (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1824 (math-combine-prod a b nil t nil))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1825 (and (math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1826 (if (math-infinitep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1827 '(var nan var-nan)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1828 (if (or (equal a '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1829 (equal a '(var uinf var-uinf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1830 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1831 (if (equal a '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1832 (if (or (math-posp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1833 (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1834 (math-zerop (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1835 (if (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1836 (not (math-intv-constp b t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1837 '(intv 3 0 (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1838 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1839 (if (or (math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1840 (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1841 (math-zerop (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1842 (if (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1843 (not (math-intv-constp b t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1844 '(intv 3 (neg (var inf var-inf)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1845 (math-neg a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1846 (if (and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1847 (math-negp (nth 2 b)) (math-posp (nth 3 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1848 '(intv 3 (neg (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1849 (var inf var-inf)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1850 (and (math-infinitep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1851 (if (equal b '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1852 b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1853 (let ((calc-infinite-mode 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1854 (math-mul-zero b a))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1855 (list '/ a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1856
66862
5827a5ed37b9 (calcFunc-ldiv): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66770
diff changeset
1857 ;;; Division from the left.
5827a5ed37b9 (calcFunc-ldiv): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66770
diff changeset
1858 (defun calcFunc-ldiv (a b)
66866
28b28c1cd22f (calcFunc-ldiv): Check to see if the first argument is a scalar.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66862
diff changeset
1859 (if (math-known-scalarp a)
28b28c1cd22f (calcFunc-ldiv): Check to see if the first argument is a scalar.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66862
diff changeset
1860 (math-div b a)
28b28c1cd22f (calcFunc-ldiv): Check to see if the first argument is a scalar.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66862
diff changeset
1861 (math-mul (math-pow a -1) b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1862
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1863 (defun calcFunc-mod (a b)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1864 (math-normalize (list '% a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1865
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1866 (defun math-mod-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1867 (cond ((equal b '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1868 (if (or (math-posp a) (math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1869 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1870 (if (math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1871 b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1872 (if (eq (car-safe a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1873 (if (math-negp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1874 '(intv 3 0 (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1875 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1876 (list '% a b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1877 ((and (eq (car-safe a) 'mod) (Math-realp b) (math-posp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1878 (math-make-mod (nth 1 a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1879 ((and (eq (car-safe a) 'intv) (math-intv-constp a t) (math-posp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1880 (math-mod-intv a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1881 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1882 (if (Math-anglep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1883 (calc-record-why 'anglep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1884 (calc-record-why 'anglep a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1885 (list '% a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1886
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1887
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1888 (defun calcFunc-pow (a b)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1889 (math-normalize (list '^ a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1890
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1891 (defun math-pow-of-zero (a b)
58626
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1892 "Raise A to the power of B, where A is a form of zero."
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1893 (if (math-floatp b) (setq a (math-float a)))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1894 (cond
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1895 ;; 0^0 = 1
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1896 ((eq b 0)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1897 1)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1898 ;; 0^0.0, etc., are undetermined
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1899 ((Math-zerop b)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1900 (if calc-infinite-mode
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1901 '(var nan var-nan)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1902 (math-reject-arg (list '^ a b) "*Indeterminate form")))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1903 ;; 0^positive = 0
58688
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
1904 ((math-known-posp b)
58626
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1905 a)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1906 ;; 0^negative is undefined (let math-div handle it)
58688
e5b1db7d4396 (math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58647
diff changeset
1907 ((math-known-negp b)
58626
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1908 (math-div 1 a))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1909 ;; 0^infinity is undefined
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1910 ((math-infinitep b)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1911 '(var nan var-nan))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1912 ;; Some intervals
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1913 ((and (eq (car b) 'intv)
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1914 calc-infinite-mode
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1915 (math-negp (nth 2 b))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1916 (math-posp (nth 3 b)))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1917 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)))
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1918 ;; If none of the above, leave it alone.
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1919 (t
f6af195898b4 (math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58510
diff changeset
1920 (list '^ a b))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1921
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1922 (defun math-pow-zero (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1923 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1924 (math-make-mod 1 (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1925 (if (math-known-matrixp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1926 (math-mimic-ident 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1927 (if (math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1928 '(var nan var-nan)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1929 (if (and (eq (car a) 'intv) (math-intv-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1930 (or (and (not (math-posp a)) (not (math-negp a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1931 (not (math-intv-constp a t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1932 '(intv 3 (neg (var inf var-inf)) (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1933 (if (or (math-floatp a) (math-floatp b))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1934 '(float 1 0) 1))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1935
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1936 (defun math-pow-fancy (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1937 (cond ((and (Math-numberp a) (Math-numberp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1938 (or (if (memq (math-quarter-integer b) '(1 2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1939 (let ((sqrt (math-sqrt (if (math-floatp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1940 (math-float a) a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1941 (and (Math-numberp sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1942 (math-pow sqrt (math-mul 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1943 (and (eq (car b) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1944 (integerp (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1945 (<= (nth 2 b) 10)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1946 (let ((root (math-nth-root a (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1947 (and root (math-ipow root (nth 1 b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1948 (and (or (eq a 10) (equal a '(float 1 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1949 (math-num-integerp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1950 (calcFunc-scf '(float 1 0) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1951 (and calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1952 (list '^ a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1953 (math-with-extra-prec 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1954 (math-exp-raw
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1955 (math-float (math-mul b (math-ln-raw (math-float a))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1956 ((or (not (Math-objvecp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1957 (not (Math-objectp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1958 (let (temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1959 (cond ((and math-simplify-only
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1960 (not (equal a math-simplify-only)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1961 (list '^ a b))
65899
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1962 ((and (eq (car-safe a) '*)
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1963 (or
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1964 (and
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1965 (math-known-matrixp (nth 1 a))
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1966 (math-known-matrixp (nth 2 a)))
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1967 (and
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1968 calc-matrix-mode
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1969 (not (eq calc-matrix-mode 'scalar))
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1970 (and (not (math-known-scalarp (nth 1 a)))
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1971 (not (math-known-scalarp (nth 2 a)))))))
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1972 (if (and (= b -1)
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1973 (math-known-square-matrixp (nth 1 a))
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1974 (math-known-square-matrixp (nth 2 a)))
66770
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
1975 (math-mul (math-pow-fancy (nth 2 a) -1)
2a1202853ff4 (math-pow-fancy): Further expand product of square matrices.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66479
diff changeset
1976 (math-pow-fancy (nth 1 a) -1))
65899
94998ac839a5 (math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
1977 (list '^ a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1978 ((and (eq (car-safe a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1979 (or (math-known-num-integerp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1980 (math-known-nonnegp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1981 (math-known-nonnegp (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1982 (math-mul (math-pow (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1983 (math-pow (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1984 ((and (eq (car-safe a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1985 (or (math-known-num-integerp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1986 (math-known-nonnegp (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1987 (math-div (math-pow (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1988 (math-pow (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1989 ((and (eq (car-safe a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1990 (math-known-nonnegp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1991 (not (math-equal-int (nth 1 a) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1992 (math-mul (math-pow (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1993 (math-pow (math-div 1 (nth 2 a)) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1994 ((and (eq (car-safe a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1995 (or (math-known-num-integerp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1996 (math-known-nonnegp (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1997 (math-pow (nth 1 a) (math-mul (nth 2 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1998 ((and (eq (car-safe a) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1999 (or (math-known-num-integerp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2000 (math-known-nonnegp (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2001 (math-pow (nth 1 a) (math-div b 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2002 ((and (eq (car-safe a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2003 (math-known-evenp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2004 (memq (math-quarter-integer b) '(1 2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2005 (math-known-realp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2006 (math-abs (math-pow (nth 1 a) (math-mul (nth 2 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2007 ((and (math-looks-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2008 (math-known-integerp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2009 (setq temp (or (and (math-known-evenp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2010 (math-pow (math-neg a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2011 (and (math-known-oddp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2012 (math-neg (math-pow (math-neg a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2013 b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2014 temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2015 ((and (eq (car-safe a) 'calcFunc-abs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2016 (math-known-realp (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2017 (math-known-evenp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2018 (math-pow (nth 1 a) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2019 ((math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2020 (cond ((equal a '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2021 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2022 ((eq (car a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2023 (math-mul (math-pow -1 b) (math-pow (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2024 ((math-posp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2025 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2026 ((math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2027 (if (math-floatp b) '(float 0 0) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2028 ((and (eq (car-safe b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2029 (math-intv-constp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2030 '(intv 3 0 (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2031 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2032 '(var nan var-nan))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2033 ((math-infinitep b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2034 (let (scale)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2035 (cond ((math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2036 (math-pow (math-div 1 a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2037 ((not (math-posp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2038 '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2039 ((math-equal-int (setq scale (calcFunc-abssqr a)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2040 '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2041 ((Math-lessp scale 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2042 (if (math-floatp a) '(float 0 0) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2043 ((Math-lessp 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2044 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2045 ((Math-lessp a -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2046 '(var uinf var-uinf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2047 ((and (eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2048 (math-intv-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2049 (if (Math-lessp -1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2050 (if (math-equal-int (nth 3 a) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2051 '(intv 3 0 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2052 '(intv 3 0 (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2053 '(intv 3 (neg (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2054 (var inf var-inf))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2055 (t (list '^ a b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2056 ((and (eq (car-safe a) 'calcFunc-idn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2057 (= (length a) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2058 (math-known-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2059 (list 'calcFunc-idn (math-pow (nth 1 a) b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2060 (t (if (Math-objectp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2061 (calc-record-why 'objectp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2062 (calc-record-why 'objectp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2063 (list '^ a b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2064 ((and (eq (car-safe a) 'sdev) (eq (car-safe b) 'sdev))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2065 (if (and (math-constp a) (math-constp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2066 (math-with-extra-prec 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2067 (let* ((ln (math-ln-raw (math-float (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2068 (pow (math-exp-raw
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2069 (math-float (math-mul (nth 1 b) ln)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2070 (math-make-sdev
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2071 pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2072 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2073 pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2074 (math-hypot (math-mul (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2075 (math-div (nth 1 b) (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2076 (math-mul (nth 2 b) ln))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2077 (let ((pow (math-pow (nth 1 a) (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2078 (math-make-sdev
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2079 pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2080 (math-mul pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2081 (math-hypot (math-mul (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2082 (math-div (nth 1 b) (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2083 (math-mul (nth 2 b) (calcFunc-ln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2084 (nth 1 a)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2085 ((and (eq (car-safe a) 'sdev) (Math-numberp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2086 (if (math-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2087 (math-with-extra-prec 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2088 (let ((pow (math-pow (nth 1 a) (math-sub b 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2089 (math-make-sdev (math-mul pow (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2090 (math-mul pow (math-mul (nth 2 a) b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2091 (math-make-sdev (math-pow (nth 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2092 (math-mul (math-pow (nth 1 a) (math-add b -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2093 (math-mul (nth 2 a) b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2094 ((and (eq (car-safe b) 'sdev) (Math-numberp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2095 (math-with-extra-prec 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2096 (let* ((ln (math-ln-raw (math-float a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2097 (pow (calcFunc-exp (math-mul (nth 1 b) ln))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2098 (math-make-sdev pow (math-mul pow (math-mul (nth 2 b) ln))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2099 ((and (eq (car-safe a) 'intv) (math-intv-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2100 (Math-realp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2101 (or (Math-natnump b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2102 (Math-posp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2103 (and (math-zerop (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2104 (or (Math-posp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2105 (and (Math-integerp b) calc-infinite-mode)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2106 (Math-negp (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2107 (and (math-zerop (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2108 (or (Math-posp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2109 (and (Math-integerp b) calc-infinite-mode)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2110 (if (math-evenp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2111 (setq a (math-abs a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2112 (let ((calc-infinite-mode (if (math-zerop (nth 3 a)) -1 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2113 (math-sort-intv (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2114 (math-pow (nth 2 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2115 (math-pow (nth 3 a) b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2116 ((and (eq (car-safe b) 'intv) (math-intv-constp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2117 (Math-realp a) (Math-posp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2118 (math-sort-intv (nth 1 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2119 (math-pow a (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2120 (math-pow a (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2121 ((and (eq (car-safe a) 'intv) (math-intv-constp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2122 (eq (car-safe b) 'intv) (math-intv-constp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2123 (or (and (not (Math-negp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2124 (not (Math-negp (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2125 (and (Math-posp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2126 (not (Math-posp (nth 3 b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2127 (let ((lo (math-pow a (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2128 (hi (math-pow a (nth 3 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2129 (or (eq (car-safe lo) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2130 (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0) lo lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2131 (or (eq (car-safe hi) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2132 (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0) hi hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2133 (math-combine-intervals
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2134 (nth 2 lo) (and (or (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2135 (math-infinitep (nth 2 lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2136 (memq (nth 1 lo) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2137 (nth 3 lo) (and (or (memq (nth 1 b) '(2 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2138 (math-infinitep (nth 3 lo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2139 (memq (nth 1 lo) '(1 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2140 (nth 2 hi) (and (or (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2141 (math-infinitep (nth 2 hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2142 (memq (nth 1 hi) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2143 (nth 3 hi) (and (or (memq (nth 1 b) '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2144 (math-infinitep (nth 3 hi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2145 (memq (nth 1 hi) '(1 3))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2146 ((and (eq (car-safe a) 'mod) (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2147 (equal (nth 2 a) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2148 (math-make-mod (math-pow-mod (nth 1 a) (nth 1 b) (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2149 (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2150 ((and (eq (car-safe a) 'mod) (Math-anglep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2151 (math-make-mod (math-pow-mod (nth 1 a) b (nth 2 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2152 ((and (eq (car-safe b) 'mod) (Math-anglep a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2153 (math-make-mod (math-pow-mod a (nth 1 b) (nth 2 b)) (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2154 ((not (Math-numberp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2155 (math-reject-arg a 'numberp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2156 (t
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2157 (math-reject-arg b 'numberp))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2158
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2159 (defun math-quarter-integer (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2160 (if (Math-integerp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2161 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2162 (if (math-negp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2163 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2164 (setq x (math-quarter-integer (math-neg x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2165 (and x (- 4 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2166 (if (eq (car x) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2167 (if (eq (nth 2 x) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2168 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2169 (and (eq (nth 2 x) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2170 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2171 (setq x (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2172 (% (if (consp x) (nth 1 x) x) 4))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2173 (if (eq (car x) 'float)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2174 (if (>= (nth 2 x) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2175 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2176 (if (= (nth 2 x) -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2177 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2178 (setq x (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2179 (and (= (% (if (consp x) (nth 1 x) x) 10) 5) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2180 (if (= (nth 2 x) -2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2181 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2182 (setq x (nth 1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2183 x (% (if (consp x) (nth 1 x) x) 100))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2184 (if (= x 25) 1
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2185 (if (= x 75) 3)))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2186
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2187 ;;; This assumes A < M and M > 0.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2188 (defun math-pow-mod (a b m) ; [R R R R]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2189 (if (and (Math-integerp a) (Math-integerp b) (Math-integerp m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2190 (if (Math-negp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2191 (math-div-mod 1 (math-pow-mod a (Math-integer-neg b) m) m)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2192 (if (eq m 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2193 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2194 (math-pow-mod-step a b m)))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2195 (math-mod (math-pow a b) m)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2196
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2197 (defun math-pow-mod-step (a n m) ; [I I I I]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2198 (math-working "pow" a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2199 (let ((val (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2200 ((eq n 0) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2201 ((eq n 1) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2202 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2203 (let ((rest (math-pow-mod-step
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2204 (math-imod (math-mul a a) m)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2205 (math-div2 n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2206 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2207 (if (math-evenp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2208 rest
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2209 (math-mod (math-mul a rest) m)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2210 (math-working "pow" val)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2211 val))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2212
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2213
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2214 ;;; Compute the minimum of two real numbers. [R R R] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2215 (defun math-min (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2216 (if (and (consp a) (eq (car a) 'intv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2217 (if (and (consp b) (eq (car b) 'intv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2218 (let ((lo (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2219 (lom (memq (nth 1 a) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2220 (hi (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2221 (him (memq (nth 1 a) '(1 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2222 res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2223 (if (= (setq res (math-compare (nth 2 b) lo)) -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2224 (setq lo (nth 2 b) lom (memq (nth 1 b) '(2 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2225 (if (= res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2226 (setq lom (or lom (memq (nth 1 b) '(2 3))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2227 (if (= (setq res (math-compare (nth 3 b) hi)) -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2228 (setq hi (nth 3 b) him (memq (nth 1 b) '(1 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2229 (if (= res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2230 (setq him (or him (memq (nth 1 b) '(1 3))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2231 (math-make-intv (+ (if lom 2 0) (if him 1 0)) lo hi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2232 (math-min a (list 'intv 3 b b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2233 (if (and (consp b) (eq (car b) 'intv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2234 (math-min (list 'intv 3 a a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2235 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2236 (if (= res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2237 b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2238 (if (= res 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2239 '(var nan var-nan)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2240 a))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2241
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2242 (defun calcFunc-min (&optional a &rest b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2243 (if (not a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2244 '(var inf var-inf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2245 (if (not (or (Math-anglep a) (eq (car a) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2246 (and (eq (car a) 'intv) (math-intv-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2247 (math-infinitep a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2248 (math-reject-arg a 'anglep))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2249 (math-min-list a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2250
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2251 (defun math-min-list (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2252 (if b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2253 (if (or (Math-anglep (car b)) (eq (car b) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2254 (and (eq (car (car b)) 'intv) (math-intv-constp (car b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2255 (math-infinitep (car b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2256 (math-min-list (math-min a (car b)) (cdr b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2257 (math-reject-arg (car b) 'anglep))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2258 a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2259
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2260 ;;; Compute the maximum of two real numbers. [R R R] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2261 (defun math-max (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2262 (if (or (and (consp a) (eq (car a) 'intv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2263 (and (consp b) (eq (car b) 'intv)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2264 (math-neg (math-min (math-neg a) (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2265 (let ((res (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2266 (if (= res -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2267 b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2268 (if (= res 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2269 '(var nan var-nan)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2270 a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2271
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2272 (defun calcFunc-max (&optional a &rest b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2273 (if (not a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2274 '(neg (var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2275 (if (not (or (Math-anglep a) (eq (car a) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2276 (and (eq (car a) 'intv) (math-intv-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2277 (math-infinitep a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2278 (math-reject-arg a 'anglep))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2279 (math-max-list a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2280
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2281 (defun math-max-list (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2282 (if b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2283 (if (or (Math-anglep (car b)) (eq (car b) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2284 (and (eq (car (car b)) 'intv) (math-intv-constp (car b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2285 (math-infinitep (car b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2286 (math-max-list (math-max a (car b)) (cdr b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2287 (math-reject-arg (car b) 'anglep))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2288 a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2289
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2290
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2291 ;;; Compute the absolute value of A. [O O; r r] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2292 (defun math-abs (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2293 (cond ((Math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2294 (math-neg a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2295 ((Math-anglep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2296 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2297 ((eq (car a) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2298 (math-hypot (nth 1 a) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2299 ((eq (car a) 'polar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2300 (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2301 ((eq (car a) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2302 (if (cdr (cdr (cdr a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2303 (math-sqrt (calcFunc-abssqr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2304 (if (cdr (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2305 (math-hypot (nth 1 a) (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2306 (if (cdr a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2307 (math-abs (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2308 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2309 ((eq (car a) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2310 (list 'sdev (math-abs (nth 1 a)) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2311 ((and (eq (car a) 'intv) (math-intv-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2312 (if (Math-posp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2313 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2314 (let* ((nlo (math-neg (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2315 (res (math-compare nlo (nth 3 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2316 (cond ((= res 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2317 (math-make-intv (if (memq (nth 1 a) '(0 1)) 2 3) 0 nlo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2318 ((= res 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2319 (math-make-intv (if (eq (nth 1 a) 0) 2 3) 0 nlo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2320 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2321 (math-make-intv (if (memq (nth 1 a) '(0 2)) 2 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2322 0 (nth 3 a)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2323 ((math-looks-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2324 (list 'calcFunc-abs (math-neg a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2325 ((let ((signs (math-possible-signs a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2326 (or (and (memq signs '(2 4 6)) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2327 (and (memq signs '(1 3)) (math-neg a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2328 ((let ((inf (math-infinitep a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2329 (and inf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2330 (if (equal inf '(var nan var-nan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2331 inf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2332 '(var inf var-inf)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2333 (t (calc-record-why 'numvecp a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2334 (list 'calcFunc-abs a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2335
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2336 (defalias 'calcFunc-abs 'math-abs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2337
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2338 (defun math-float-fancy (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2339 (cond ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2340 (cons (car a) (cons (nth 1 a) (mapcar 'math-float (nthcdr 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2341 ((and (memq (car a) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2342 (math-numberp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2343 (list (car a) (math-float (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2344 (list 'calcFunc-float (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2345 ((and (eq (car a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2346 (eq (car (nth 1 a)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2347 (math-numberp (nth 1 (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2348 (list '* (math-float (nth 1 (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2349 (list 'calcFunc-float (list '/ (nth 2 (nth 1 a)) (nth 2 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2350 ((math-infinitep a) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2351 ((eq (car a) 'calcFunc-float) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2352 ((let ((func (assq (car a) '((calcFunc-floor . calcFunc-ffloor)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2353 (calcFunc-ceil . calcFunc-fceil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2354 (calcFunc-trunc . calcFunc-ftrunc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2355 (calcFunc-round . calcFunc-fround)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2356 (calcFunc-rounde . calcFunc-frounde)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2357 (calcFunc-roundu . calcFunc-froundu)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2358 (and func (cons (cdr func) (cdr a)))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2359 (t (math-reject-arg a 'objectp))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2360
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2361 (defalias 'calcFunc-float 'math-float)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2362
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2363 ;; The variable math-trunc-prec is local to math-trunc in calc-misc.el,
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2364 ;; but used by math-trunc-fancy which is called by math-trunc.
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2365 (defvar math-trunc-prec)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2366
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2367 (defun math-trunc-fancy (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2368 (cond ((eq (car a) 'frac) (math-quotient (nth 1 a) (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2369 ((eq (car a) 'cplx) (math-trunc (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2370 ((eq (car a) 'polar) (math-trunc (math-complex a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2371 ((eq (car a) 'hms) (list 'hms (nth 1 a) 0 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2372 ((eq (car a) 'date) (list 'date (math-trunc (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2373 ((eq (car a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2374 (if (math-messy-integerp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2375 (math-trunc (math-make-mod (nth 1 a) (math-trunc (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2376 (math-make-mod (math-trunc (nth 1 a)) (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2377 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2378 (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2379 (memq (nth 1 a) '(0 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2380 0 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2381 (if (and (equal (nth 3 a) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2382 (memq (nth 1 a) '(0 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2383 0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2384 (if (and (Math-negp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2385 (Math-num-integerp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2386 (memq (nth 1 a) '(0 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2387 (math-add (math-trunc (nth 2 a)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2388 (math-trunc (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2389 (if (and (Math-posp (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2390 (Math-num-integerp (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2391 (memq (nth 1 a) '(0 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2392 (math-add (math-trunc (nth 3 a)) -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2393 (math-trunc (nth 3 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2394 ((math-provably-integerp a) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2395 ((Math-vectorp a)
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2396 (math-map-vec (function (lambda (x) (math-trunc x math-trunc-prec))) a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2397 ((math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2398 (if (or (math-posp a) (math-negp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2399 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2400 '(var nan var-nan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2401 ((math-to-integer a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2402 (t (math-reject-arg a 'numberp))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2403
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2404 (defun math-trunc-special (a prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2405 (if (Math-messy-integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2406 (setq prec (math-trunc prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2407 (or (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2408 (math-reject-arg prec 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2409 (if (and (<= prec 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2410 (math-provably-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2411 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2412 (calcFunc-scf (math-trunc (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2413 (calcFunc-scf a prec)))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2414 (- prec))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2415
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2416 (defun math-to-integer (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2417 (let ((func (assq (car-safe a) '((calcFunc-ffloor . calcFunc-floor)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2418 (calcFunc-fceil . calcFunc-ceil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2419 (calcFunc-ftrunc . calcFunc-trunc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2420 (calcFunc-fround . calcFunc-round)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2421 (calcFunc-frounde . calcFunc-rounde)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2422 (calcFunc-froundu . calcFunc-roundu)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2423 (and func (= (length a) 2)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2424 (cons (cdr func) (cdr a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2425
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2426 (defun calcFunc-ftrunc (a &optional prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2427 (if (and (Math-messy-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2428 (or (not prec) (and (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2429 (<= prec 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2430 a
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2431 (math-float (math-trunc a prec))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2432
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2433 ;; The variable math-floor-prec is local to math-floor in calc-misc.el,
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2434 ;; but used by math-floor-fancy which is called by math-floor.
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2435 (defvar math-floor-prec)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2436
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2437 (defun math-floor-fancy (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2438 (cond ((math-provably-integerp a) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2439 ((eq (car a) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2440 (if (or (math-posp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2441 (and (math-zerop (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2442 (math-zerop (nth 3 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2443 (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2444 (math-add (math-trunc a) -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2445 ((eq (car a) 'date) (list 'date (math-floor (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2446 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2447 (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2448 (memq (nth 1 a) '(0 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2449 0 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2450 (if (and (equal (nth 3 a) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2451 (memq (nth 1 a) '(0 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2452 0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2453 (math-floor (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2454 (if (and (Math-num-integerp (nth 3 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2455 (memq (nth 1 a) '(0 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2456 (math-add (math-floor (nth 3 a)) -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2457 (math-floor (nth 3 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2458 ((Math-vectorp a)
58510
b1042b68790c Finish making previous change.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58479
diff changeset
2459 (math-map-vec (function (lambda (x) (math-floor x math-floor-prec))) a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2460 ((math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2461 (if (or (math-posp a) (math-negp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2462 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2463 '(var nan var-nan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2464 ((math-to-integer a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2465 (t (math-reject-arg a 'anglep))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2466
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2467 (defun math-floor-special (a prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2468 (if (Math-messy-integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2469 (setq prec (math-trunc prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2470 (or (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2471 (math-reject-arg prec 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2472 (if (and (<= prec 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2473 (math-provably-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2474 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2475 (calcFunc-scf (math-floor (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2476 (calcFunc-scf a prec)))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2477 (- prec))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2478
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2479 (defun calcFunc-ffloor (a &optional prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2480 (if (and (Math-messy-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2481 (or (not prec) (and (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2482 (<= prec 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2483 a
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2484 (math-float (math-floor a prec))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2485
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2486 ;;; Coerce A to be an integer (by truncation toward plus infinity). [I N]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2487 (defun math-ceiling (a &optional prec) ; [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2488 (cond (prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2489 (if (Math-messy-integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2490 (setq prec (math-trunc prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2491 (or (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2492 (math-reject-arg prec 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2493 (if (and (<= prec 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2494 (math-provably-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2495 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2496 (calcFunc-scf (math-ceiling (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2497 (calcFunc-scf a prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2498 (- prec))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2499 ((Math-integerp a) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2500 ((Math-messy-integerp a) (math-trunc a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2501 ((Math-realp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2502 (if (Math-posp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2503 (math-add (math-trunc a) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2504 (math-trunc a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2505 ((math-provably-integerp a) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2506 ((eq (car a) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2507 (if (or (math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2508 (and (math-zerop (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2509 (math-zerop (nth 3 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2510 (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2511 (math-add (math-trunc a) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2512 ((eq (car a) 'date) (list 'date (math-ceiling (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2513 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2514 (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2515 (memq (nth 1 a) '(0 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2516 0 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2517 (if (and (equal (nth 3 a) '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2518 (memq (nth 1 a) '(0 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2519 0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2520 (if (and (Math-num-integerp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2521 (memq (nth 1 a) '(0 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2522 (math-add (math-floor (nth 2 a)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2523 (math-ceiling (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2524 (math-ceiling (nth 3 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2525 ((Math-vectorp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2526 (math-map-vec (function (lambda (x) (math-ceiling x prec))) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2527 ((math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2528 (if (or (math-posp a) (math-negp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2529 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2530 '(var nan var-nan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2531 ((math-to-integer a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2532 (t (math-reject-arg a 'anglep))))
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2533
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2534 (defalias 'calcFunc-ceil 'math-ceiling)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2535
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2536 (defun calcFunc-fceil (a &optional prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2537 (if (and (Math-messy-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2538 (or (not prec) (and (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2539 (<= prec 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2540 a
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2541 (math-float (math-ceiling a prec))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2542
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
2543 (defvar math-rounding-mode nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2544
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2545 ;;; Coerce A to be an integer (by rounding to nearest integer). [I N] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2546 (defun math-round (a &optional prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2547 (cond (prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2548 (if (Math-messy-integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2549 (setq prec (math-trunc prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2550 (or (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2551 (math-reject-arg prec 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2552 (if (and (<= prec 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2553 (math-provably-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2554 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2555 (calcFunc-scf (math-round (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2556 (calcFunc-scf a prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2557 (- prec))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2558 ((Math-anglep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2559 (if (Math-num-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2560 (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2561 (if (and (Math-negp a) (not (eq math-rounding-mode 'up)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2562 (math-neg (math-round (math-neg a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2563 (setq a (let ((calc-angle-mode 'deg)) ; in case of HMS forms
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2564 (math-add a (if (Math-ratp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2565 '(frac 1 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2566 '(float 5 -1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2567 (if (and (Math-num-integerp a) (eq math-rounding-mode 'even))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2568 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2569 (setq a (math-floor a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2570 (or (math-evenp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2571 (setq a (math-sub a 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2572 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2573 (math-floor a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2574 ((math-provably-integerp a) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2575 ((eq (car a) 'date) (list 'date (math-round (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2576 ((eq (car a) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2577 (math-floor (math-add a '(frac 1 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2578 ((Math-vectorp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2579 (math-map-vec (function (lambda (x) (math-round x prec))) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2580 ((math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2581 (if (or (math-posp a) (math-negp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2582 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2583 '(var nan var-nan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2584 ((math-to-integer a))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2585 (t (math-reject-arg a 'anglep))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2586
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2587 (defalias 'calcFunc-round 'math-round)
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2588
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2589 (defsubst calcFunc-rounde (a &optional prec)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2590 (let ((math-rounding-mode 'even))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2591 (math-round a prec)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2592
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2593 (defsubst calcFunc-roundu (a &optional prec)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2594 (let ((math-rounding-mode 'up))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2595 (math-round a prec)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2596
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2597 (defun calcFunc-fround (a &optional prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2598 (if (and (Math-messy-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2599 (or (not prec) (and (integerp prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2600 (<= prec 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2601 a
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2602 (math-float (math-round a prec))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2603
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2604 (defsubst calcFunc-frounde (a &optional prec)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2605 (let ((math-rounding-mode 'even))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2606 (calcFunc-fround a prec)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2607
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2608 (defsubst calcFunc-froundu (a &optional prec)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2609 (let ((math-rounding-mode 'up))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2610 (calcFunc-fround a prec)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2611
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2612 ;;; Pull floating-point values apart into mantissa and exponent.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2613 (defun calcFunc-mant (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2614 (if (Math-realp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2615 (if (or (Math-ratp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2616 (eq (nth 1 x) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2617 x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2618 (list 'float (nth 1 x) (- 1 (math-numdigs (nth 1 x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2619 (calc-record-why 'realp x)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2620 (list 'calcFunc-mant x)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2621
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2622 (defun calcFunc-xpon (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2623 (if (Math-realp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2624 (if (or (Math-ratp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2625 (eq (nth 1 x) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2626 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2627 (math-normalize (+ (nth 2 x) (1- (math-numdigs (nth 1 x))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2628 (calc-record-why 'realp x)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2629 (list 'calcFunc-xpon x)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2630
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2631 (defun calcFunc-scf (x n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2632 (if (integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2633 (cond ((eq n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2634 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2635 ((Math-integerp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2636 (if (> n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2637 (math-scale-int x n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2638 (math-div x (math-scale-int 1 (- n)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2639 ((eq (car x) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2640 (if (> n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2641 (math-make-frac (math-scale-int (nth 1 x) n) (nth 2 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2642 (math-make-frac (nth 1 x) (math-scale-int (nth 2 x) (- n)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2643 ((eq (car x) 'float)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2644 (math-make-float (nth 1 x) (+ (nth 2 x) n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2645 ((memq (car x) '(cplx sdev))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2646 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2647 (list (car x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2648 (calcFunc-scf (nth 1 x) n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2649 (calcFunc-scf (nth 2 x) n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2650 ((memq (car x) '(polar mod))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2651 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2652 (list (car x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2653 (calcFunc-scf (nth 1 x) n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2654 (nth 2 x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2655 ((eq (car x) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2656 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2657 (list (car x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2658 (nth 1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2659 (calcFunc-scf (nth 2 x) n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2660 (calcFunc-scf (nth 3 x) n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2661 ((eq (car x) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2662 (math-map-vec (function (lambda (x) (calcFunc-scf x n))) x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2663 ((math-infinitep x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2664 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2665 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2666 (calc-record-why 'realp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2667 (list 'calcFunc-scf x n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2668 (if (math-messy-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2669 (if (< (nth 2 n) 10)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2670 (calcFunc-scf x (math-trunc n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2671 (math-overflow n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2672 (if (math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2673 (math-overflow n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2674 (calc-record-why 'integerp n)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2675 (list 'calcFunc-scf x n)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2676
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2677
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2678 (defun calcFunc-incr (x &optional step relative-to)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2679 (or step (setq step 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2680 (cond ((not (Math-integerp step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2681 (math-reject-arg step 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2682 ((Math-integerp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2683 (math-add x step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2684 ((eq (car x) 'float)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2685 (if (and (math-zerop x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2686 (eq (car-safe relative-to) 'float))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2687 (math-mul step
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2688 (calcFunc-scf relative-to (- 1 calc-internal-prec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2689 (math-add-float x (math-make-float
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2690 step
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2691 (+ (nth 2 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2692 (- (math-numdigs (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2693 calc-internal-prec))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2694 ((eq (car x) 'date)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2695 (if (Math-integerp (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2696 (math-add x step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2697 (math-add x (list 'hms 0 0 step))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2698 (t
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2699 (math-reject-arg x 'realp))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2700
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2701 (defsubst calcFunc-decr (x &optional step relative-to)
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2702 (calcFunc-incr x (math-neg (or step 1)) relative-to))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2703
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2704 (defun calcFunc-percent (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2705 (if (math-objectp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2706 (let ((calc-prefer-frac nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2707 (math-div x 100))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2708 (list 'calcFunc-percent x)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2709
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2710 (defun calcFunc-relch (x y)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2711 (if (and (math-objectp x) (math-objectp y))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2712 (math-div (math-sub y x) x)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2713 (list 'calcFunc-relch x y)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2714
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2715 ;;; Compute the absolute value squared of A. [F N] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2716 (defun calcFunc-abssqr (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2717 (cond ((Math-realp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2718 (math-mul a a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2719 ((eq (car a) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2720 (math-add (math-sqr (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2721 (math-sqr (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2722 ((eq (car a) 'polar)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2723 (math-sqr (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2724 ((and (memq (car a) '(sdev intv)) (math-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2725 (math-sqr (math-abs a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2726 ((eq (car a) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2727 (math-reduce-vec 'math-add (math-map-vec 'calcFunc-abssqr a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2728 ((math-known-realp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2729 (math-pow a 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2730 ((let ((inf (math-infinitep a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2731 (and inf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2732 (math-mul (calcFunc-abssqr (math-infinite-dir a inf)) inf))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2733 (t (calc-record-why 'numvecp a)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2734 (list 'calcFunc-abssqr a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2735
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2736 (defsubst math-sqr (a)
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2737 (math-mul a a))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2738
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2739 ;;;; Number theory.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2740
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2741 (defun calcFunc-idiv (a b) ; [I I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2742 (cond ((and (Math-natnump a) (Math-natnump b) (not (eq b 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2743 (math-quotient a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2744 ((Math-realp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2745 (if (Math-realp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2746 (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2747 (math-floor (math-div a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2748 (math-reject-arg b 'realp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2749 ((eq (car-safe a) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2750 (if (eq (car-safe b) 'hms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2751 (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2752 (math-floor (math-div a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2753 (math-reject-arg b 'hmsp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2754 ((and (or (eq (car-safe a) 'intv) (Math-realp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2755 (or (eq (car-safe b) 'intv) (Math-realp b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2756 (math-floor (math-div a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2757 ((or (math-infinitep a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2758 (math-infinitep b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2759 (math-div a b))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2760 (t (math-reject-arg a 'anglep))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2761
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2762
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2763 ;;; Combine two terms being added, if possible.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2764 (defun math-combine-sum (a b nega negb scalar-okay)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2765 (if (and scalar-okay (Math-objvecp a) (Math-objvecp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2766 (math-add-or-sub a b nega negb)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2767 (let ((amult 1) (bmult 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2768 (and (consp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2769 (cond ((and (eq (car a) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2770 (Math-objectp (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2771 (setq amult (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2772 a (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2773 ((and (eq (car a) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2774 (Math-objectp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2775 (setq amult (if (Math-integerp (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2776 (list 'frac 1 (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2777 (math-div 1 (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2778 a (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2779 ((eq (car a) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2780 (setq amult -1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2781 a (nth 1 a)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2782 (and (consp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2783 (cond ((and (eq (car b) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2784 (Math-objectp (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2785 (setq bmult (nth 1 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2786 b (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2787 ((and (eq (car b) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2788 (Math-objectp (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2789 (setq bmult (if (Math-integerp (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2790 (list 'frac 1 (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2791 (math-div 1 (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2792 b (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2793 ((eq (car b) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2794 (setq bmult -1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2795 b (nth 1 b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2796 (and (if math-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2797 (Math-equal a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2798 (equal a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2799 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2800 (if nega (setq amult (math-neg amult)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2801 (if negb (setq bmult (math-neg bmult)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2802 (setq amult (math-add amult bmult))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2803 (math-mul amult a))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2804
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2805 (defun math-add-or-sub (a b aneg bneg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2806 (if aneg (setq a (math-neg a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2807 (if bneg (setq b (math-neg b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2808 (if (or (Math-vectorp a) (Math-vectorp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2809 (math-normalize (list '+ a b))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2810 (math-add a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2811
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
2812 (defvar math-combine-prod-e '(var e var-e))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41041
diff changeset
2813
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2814 ;;; The following is expanded out four ways for speed.
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2815
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2816 ;; math-unit-prefixes is defined in calc-units.el,
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2817 ;; but used here.
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2818 (defvar math-unit-prefixes)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
2819
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2820 (defun math-combine-prod (a b inva invb scalar-okay)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2821 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2822 ((or (and inva (Math-zerop a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2823 (and invb (Math-zerop b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2824 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2825 ((and scalar-okay (Math-objvecp a) (Math-objvecp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2826 (setq a (math-mul-or-div a b inva invb))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2827 (and (Math-objvecp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2828 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2829 ((and (eq (car-safe a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2830 inva
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2831 (math-looks-negp (nth 2 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2832 (math-mul (math-pow (nth 1 a) (math-neg (nth 2 a))) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2833 ((and (eq (car-safe b) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2834 invb
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2835 (math-looks-negp (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2836 (math-mul a (math-pow (nth 1 b) (math-neg (nth 2 b)))))
60154
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2837 ((and math-simplifying
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2838 (math-combine-prod-trig a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2839 (t (let ((apow 1) (bpow 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2840 (and (consp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2841 (cond ((and (eq (car a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2842 (or math-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2843 (Math-numberp (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2844 (setq apow (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2845 a (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2846 ((eq (car a) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2847 (setq apow '(frac 1 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2848 a (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2849 ((and (eq (car a) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2850 (or math-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2851 (Math-numberp (nth 1 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2852 (setq apow (nth 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2853 a math-combine-prod-e))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2854 (and (consp a) (eq (car a) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2855 (Math-lessp (nth 1 a) (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2856 (setq a (math-div 1 a) apow (math-neg apow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2857 (and (consp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2858 (cond ((and (eq (car b) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2859 (or math-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2860 (Math-numberp (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2861 (setq bpow (nth 2 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2862 b (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2863 ((eq (car b) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2864 (setq bpow '(frac 1 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2865 b (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2866 ((and (eq (car b) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2867 (or math-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2868 (Math-numberp (nth 1 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2869 (setq bpow (nth 1 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2870 b math-combine-prod-e))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2871 (and (consp b) (eq (car b) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2872 (Math-lessp (nth 1 b) (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2873 (setq b (math-div 1 b) bpow (math-neg bpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2874 (if inva (setq apow (math-neg apow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2875 (if invb (setq bpow (math-neg bpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2876 (or (and (if math-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2877 (math-commutative-equal a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2878 (equal a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2879 (let ((sumpow (math-add apow bpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2880 (and (or (not (Math-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2881 (Math-zerop sumpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2882 (eq (eq (car-safe apow) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2883 (eq (car-safe bpow) 'frac)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2884 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2885 (and (math-looks-negp sumpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2886 (Math-ratp a) (Math-posp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2887 (setq a (math-div 1 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2888 sumpow (math-neg sumpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2889 (cond ((equal sumpow '(frac 1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2890 (list 'calcFunc-sqrt a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2891 ((equal sumpow '(frac -1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2892 (math-div 1 (list 'calcFunc-sqrt a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2893 ((and (eq a math-combine-prod-e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2894 (eq a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2895 (list 'calcFunc-exp sumpow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2896 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2897 (condition-case err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2898 (math-pow a sumpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2899 (inexact-result (list '^ a sumpow)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2900 (and math-simplifying-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2901 math-combining-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2902 (let* ((ua (math-check-unit-name a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2903 ub)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2904 (and ua
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2905 (eq ua (setq ub (math-check-unit-name b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2906 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2907 (setq ua (if (eq (nth 1 a) (car ua))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2908 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2909 (nth 1 (assq (aref (symbol-name (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2910 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2911 math-unit-prefixes)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2912 ub (if (eq (nth 1 b) (car ub))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2913 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2914 (nth 1 (assq (aref (symbol-name (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2915 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2916 math-unit-prefixes))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2917 (if (Math-lessp ua ub)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2918 (let (temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2919 (setq temp a a b b temp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2920 temp ua ua ub ub temp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2921 temp apow apow bpow bpow temp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2922 (math-mul (math-pow (math-div ua ub) apow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2923 (math-pow b (math-add apow bpow)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2924 (and (equal apow bpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2925 (Math-natnump a) (Math-natnump b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2926 (cond ((equal apow '(frac 1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2927 (list 'calcFunc-sqrt (math-mul a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2928 ((equal apow '(frac -1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2929 (math-div 1 (list 'calcFunc-sqrt (math-mul a b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2930 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2931 (setq a (math-mul a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2932 (condition-case err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2933 (math-pow a apow)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2934 (inexact-result (list '^ a apow)))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2935
60154
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2936 (defun math-combine-prod-trig (a b)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2937 (cond
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2938 ((and (eq (car-safe a) 'calcFunc-sin)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2939 (eq (car-safe b) 'calcFunc-csc)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2940 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2941 1)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2942 ((and (eq (car-safe a) 'calcFunc-sin)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2943 (eq (car-safe b) 'calcFunc-sec)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2944 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2945 (cons 'calcFunc-tan (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2946 ((and (eq (car-safe a) 'calcFunc-sin)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2947 (eq (car-safe b) 'calcFunc-cot)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2948 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2949 (cons 'calcFunc-cos (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2950 ((and (eq (car-safe a) 'calcFunc-cos)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2951 (eq (car-safe b) 'calcFunc-sec)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2952 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2953 1)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2954 ((and (eq (car-safe a) 'calcFunc-cos)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2955 (eq (car-safe b) 'calcFunc-csc)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2956 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2957 (cons 'calcFunc-cot (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2958 ((and (eq (car-safe a) 'calcFunc-cos)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2959 (eq (car-safe b) 'calcFunc-tan)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2960 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2961 (cons 'calcFunc-sin (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2962 ((and (eq (car-safe a) 'calcFunc-tan)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2963 (eq (car-safe b) 'calcFunc-cot)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2964 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2965 1)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2966 ((and (eq (car-safe a) 'calcFunc-tan)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2967 (eq (car-safe b) 'calcFunc-csc)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2968 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2969 (cons 'calcFunc-sec (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2970 ((and (eq (car-safe a) 'calcFunc-sec)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2971 (eq (car-safe b) 'calcFunc-cot)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2972 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2973 (cons 'calcFunc-csc (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2974 ((and (eq (car-safe a) 'calcFunc-sinh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2975 (eq (car-safe b) 'calcFunc-csch)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2976 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2977 1)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2978 ((and (eq (car-safe a) 'calcFunc-sinh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2979 (eq (car-safe b) 'calcFunc-sech)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2980 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2981 (cons 'calcFunc-tanh (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2982 ((and (eq (car-safe a) 'calcFunc-sinh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2983 (eq (car-safe b) 'calcFunc-coth)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2984 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2985 (cons 'calcFunc-cosh (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2986 ((and (eq (car-safe a) 'calcFunc-cosh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2987 (eq (car-safe b) 'calcFunc-sech)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2988 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2989 1)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2990 ((and (eq (car-safe a) 'calcFunc-cosh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2991 (eq (car-safe b) 'calcFunc-csch)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2992 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2993 (cons 'calcFunc-coth (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2994 ((and (eq (car-safe a) 'calcFunc-cosh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2995 (eq (car-safe b) 'calcFunc-tanh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2996 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2997 (cons 'calcFunc-sinh (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2998 ((and (eq (car-safe a) 'calcFunc-tanh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
2999 (eq (car-safe b) 'calcFunc-coth)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3000 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3001 1)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3002 ((and (eq (car-safe a) 'calcFunc-tanh)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3003 (eq (car-safe b) 'calcFunc-csch)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3004 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3005 (cons 'calcFunc-sech (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3006 ((and (eq (car-safe a) 'calcFunc-sech)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3007 (eq (car-safe b) 'calcFunc-coth)
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3008 (= 0 (math-simplify (math-sub (cdr a) (cdr b)))))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3009 (cons 'calcFunc-csch (cdr a)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3010 (t
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3011 nil)))
71985e6ee53a (math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 60077
diff changeset
3012
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3013 (defun math-mul-or-div (a b ainv binv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3014 (if (or (Math-vectorp a) (Math-vectorp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3015 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3016 (if ainv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3017 (if binv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3018 (list '/ (math-div 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3019 (list '/ b a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3020 (if binv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3021 (list '/ a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3022 (list '* a b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3023 (if ainv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3024 (if binv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3025 (math-div (math-div 1 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3026 (math-div b a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3027 (if binv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3028 (math-div a b)
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3029 (math-mul a b)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3030
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3031 ;; The variable math-com-bterms is local to math-commutative-equal,
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3032 ;; but is used by math-commutative collect, which is called by
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3033 ;; math-commutative-equal.
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3034 (defvar math-com-bterms)
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3035
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3036 (defun math-commutative-equal (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3037 (if (memq (car-safe a) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3038 (and (memq (car-safe b) '(+ -))
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3039 (let ((math-com-bterms nil) aterms p)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3040 (math-commutative-collect b nil)
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3041 (setq aterms math-com-bterms math-com-bterms nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3042 (math-commutative-collect a nil)
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3043 (and (= (length aterms) (length math-com-bterms))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3044 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3045 (while (and aterms
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3046 (progn
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3047 (setq p math-com-bterms)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3048 (while (and p (not (equal (car aterms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3049 (car p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3050 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3051 p))
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3052 (setq math-com-bterms (delq (car p) math-com-bterms)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3053 aterms (cdr aterms)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3054 (not aterms)))))
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3055 (equal a b)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3056
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3057 (defun math-commutative-collect (b neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3058 (if (eq (car-safe b) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3059 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3060 (math-commutative-collect (nth 1 b) neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3061 (math-commutative-collect (nth 2 b) neg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3062 (if (eq (car-safe b) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3063 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3064 (math-commutative-collect (nth 1 b) neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3065 (math-commutative-collect (nth 2 b) (not neg)))
58479
562c6a62c99e (math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
3066 (setq math-com-bterms (cons (if neg (math-neg b) b) math-com-bterms)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3067
58647
e655efbeebac Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58626
diff changeset
3068 (provide 'calc-arith)
e655efbeebac Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58626
diff changeset
3069
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79702
diff changeset
3070 ;; arch-tag: 6c396b5b-14c6-40ed-bb2a-7cc2e8111465
41041
45130b458dac (calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3071 ;;; calc-arith.el ends here