annotate lisp/calc/calc-bin.el @ 40910:c07c0f7a2c8e

(calc-record-compilation-date-macro): Return a simple `setq' form.
author Eli Zaretskii <eliz@gnu.org>
date Sun, 11 Nov 2001 10:27:32 +0000
parents 2fb9d407ae73
children a78b609cb4b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1 ;; Calculator for GNU Emacs, part II [calc-bin.el]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3 ;; Written by Dave Gillespie, daveg@synaptics.com.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
4
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
6
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
7 ;; GNU Emacs is distributed in the hope that it will be useful,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8 ;; but WITHOUT ANY WARRANTY. No author or distributor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; accepts responsibility to anyone for the consequences of using it
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10 ;; or for whether it serves any particular purpose or works at all,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12 ;; License for full details.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14 ;; Everyone is granted permission to copy, modify and redistribute
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs, but only under the conditions described in the
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs General Public License. A copy of this license is
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
17 ;; supposed to have been given to you along with GNU Emacs so you
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
18 ;; can know your rights and responsibilities. It should be in a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19 ;; file named COPYING. Among other things, the copyright notice
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; and this notice must be preserved on all copies.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24 ;; This file is autoloaded from calc-ext.el.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
26
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29 (defun calc-Need-calc-bin () nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32 ;;; b-prefix binary commands.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34 (defun calc-and (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37 (calc-enter-result 2 "and"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 (append '(calcFunc-and)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 (calc-top-list-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (and n (list (prefix-numeric-value n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
41 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (defun calc-or (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (calc-enter-result 2 "or"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 (append '(calcFunc-or)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (calc-top-list-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 (and n (list (prefix-numeric-value n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (defun calc-xor (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 (calc-enter-result 2 "xor"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
56 (append '(calcFunc-xor)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57 (calc-top-list-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (and n (list (prefix-numeric-value n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61 (defun calc-diff (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 (calc-enter-result 2 "diff"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (append '(calcFunc-diff)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (calc-top-list-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (and n (list (prefix-numeric-value n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
70 (defun calc-not (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (calc-enter-result 1 "not"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (append '(calcFunc-not)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 (calc-top-list-n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76 (and n (list (prefix-numeric-value n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (defun calc-lshift-binary (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (calc-enter-result hyp "lsh"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (append '(calcFunc-lsh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85 (calc-top-list-n hyp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 (and n (list (prefix-numeric-value n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (defun calc-rshift-binary (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (calc-enter-result hyp "rsh"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (append '(calcFunc-rsh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (calc-top-list-n hyp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (and n (list (prefix-numeric-value n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (defun calc-lshift-arith (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (calc-enter-result hyp "ash"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (append '(calcFunc-ash)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
105 (calc-top-list-n hyp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 (and n (list (prefix-numeric-value n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 )
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-rshift-arith (n)
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
112 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
113 (calc-enter-result hyp "rash"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 (append '(calcFunc-rash)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (calc-top-list-n hyp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (and n (list (prefix-numeric-value n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 )
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 (defun calc-rotate-binary (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 (calc-enter-result hyp "rot"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (append '(calcFunc-rot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (calc-top-list-n hyp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (and n (list (prefix-numeric-value n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 (defun calc-clip (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (calc-enter-result 1 "clip"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 (append '(calcFunc-clip)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (calc-top-list-n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 (and n (list (prefix-numeric-value n))))))
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 (defun calc-word-size (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 (or n (setq n (read-string (format "Binary word size: (default %d) "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 calc-word-size))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (setq n (if (stringp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (if (equal n "")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145 calc-word-size
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 (if (string-match "\\`[-+]?[0-9]+\\'" n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 (string-to-int n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148 (error "Expected an integer")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (prefix-numeric-value n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (or (= n calc-word-size)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (if (> (math-abs n) 100)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152 (calc-change-mode 'calc-word-size n calc-leading-zeros)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 (calc-change-mode '(calc-word-size calc-previous-modulo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154 (list n (math-power-of-2 (math-abs n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 calc-leading-zeros)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
156 (if (< n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
157 (message "Binary word size is %d bits (2's complement)." (- n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
158 (message "Binary word size is %d bits." n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
159 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
160
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
161
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
164
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
165 ;;; d-prefix mode commands.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
166
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
167 (defun calc-radix (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
168 (interactive "NDisplay radix (2-36): ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
169 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170 (if (and (>= n 2) (<= n 36))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
171 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172 (calc-change-mode 'calc-number-radix n t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 ;; also change global value so minibuffer sees it
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174 (setq-default calc-number-radix calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (setq n calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
176 (message "Number radix is %d." n))
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (defun calc-decimal-radix ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (calc-radix 10)
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184 (defun calc-binary-radix ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 (calc-radix 2)
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (defun calc-octal-radix ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
190 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191 (calc-radix 8)
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 calc-hex-radix ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (calc-radix 16)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 (defun calc-leading-zeros (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
201 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 (if (calc-change-mode 'calc-leading-zeros n t t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203 (message "Zero-padding integers to %d digits (assuming radix %d)."
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 (let* ((calc-internal-prec 6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 (math-compute-max-digits (math-abs calc-word-size)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
206 calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 calc-number-radix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 (message "Omitting leading zeros on integers.")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212 (defvar math-power-of-2-cache (list 1 2 4 8 16 32 64 128 256 512 1024))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
213 (defvar math-big-power-of-2-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214 (defun math-power-of-2 (n) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
215 (if (and (natnump n) (<= n 100))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
216 (or (nth n math-power-of-2-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (let* ((i (length math-power-of-2-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
218 (val (nth (1- i) math-power-of-2-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219 (while (<= i n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220 (setq val (math-mul val 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221 math-power-of-2-cache (nconc math-power-of-2-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 (list val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 i (1+ i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224 val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 (let ((found (assq n math-big-power-of-2-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
226 (if found
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
227 (cdr found)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
228 (let ((po2 (math-ipow 2 n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
229 (setq math-big-power-of-2-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230 (cons (cons n po2) math-big-power-of-2-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231 po2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
232 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
233
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
234 (defun math-integer-log2 (n) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
235 (let ((i 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
236 (p math-power-of-2-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
237 val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
238 (while (and p (Math-natnum-lessp (setq val (car p)) n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
239 (setq p (cdr p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
240 i (1+ i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
241 (if p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
242 (and (equal val n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
243 i)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
244 (while (Math-natnum-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
245 (prog1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
246 (setq val (math-mul val 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
247 (setq math-power-of-2-cache (nconc math-power-of-2-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
248 (list val))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
249 n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
250 (setq i (1+ i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251 (and (equal val n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 ;;; Bitwise operations.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
259
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260 (defun calcFunc-and (a b &optional w) ; [I I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
262 (calcFunc-and a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 (math-clip (logand a b) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 ((or (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
268 (math-binary-modulo-args 'calcFunc-and a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
269 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
270 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
274 (math-and-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
275 (math-binary-arg b w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276 w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
277 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
278
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 (defun math-binary-arg (a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 (if (not (Math-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (setq a (math-trunc a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 (math-not-bignum (cdr (math-bignum-test (math-sub -1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 (math-abs (if w (math-trunc w) calc-word-size)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (cdr (Math-bignum-test a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 (defun math-binary-modulo-args (f a b w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 (let (mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (setq mod (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 a (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (if (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (if (equal mod (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (setq b (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 (math-reject-arg b "*Inconsistent modulos"))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (setq mod (nth 2 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 b (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (if (Math-messy-integerp mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301 (setq mod (math-trunc mod))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (or (Math-integerp mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (math-reject-arg mod 'integerp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (let ((bits (math-integer-log2 mod)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 (if bits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (if w
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 (if (/= w bits)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (calc-record-why
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 "*Warning: Modulo inconsistent with word size"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
310 (setq w bits))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 (calc-record-why "*Warning: Modulo is not a power of 2"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 (math-make-mod (if b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 (funcall f a b w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 (funcall f a w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 mod)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318 (defun math-and-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 (and a b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320 (let ((qa (math-div-bignum-digit a 512))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 (qb (math-div-bignum-digit b 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 (math-mul-bignum-digit (math-and-bignum (math-norm-bignum (car qa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (math-norm-bignum (car qb)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 (logand (cdr qa) (cdr qb)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (defun calcFunc-or (a b &optional w) ; [I I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
329 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
330 (calcFunc-or a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
331 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
332 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (math-clip (logior a b) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 ((or (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
336 (math-binary-modulo-args 'calcFunc-or a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
340 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 (math-or-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (math-binary-arg b w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
347 (defun math-or-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
348 (and (or a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349 (let ((qa (math-div-bignum-digit a 512))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
350 (qb (math-div-bignum-digit b 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351 (math-mul-bignum-digit (math-or-bignum (math-norm-bignum (car qa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
352 (math-norm-bignum (car qb)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 (logior (cdr qa) (cdr qb)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 (defun calcFunc-xor (a b &optional w) ; [I I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
358 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
359 (calcFunc-xor a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
363 (math-clip (logxor a b) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364 ((or (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
365 (math-binary-modulo-args 'calcFunc-xor a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
367 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
371 (math-xor-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
372 (math-binary-arg b w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373 w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
374 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
375
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
376 (defun math-xor-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
377 (and (or a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
378 (let ((qa (math-div-bignum-digit a 512))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
379 (qb (math-div-bignum-digit b 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 (math-mul-bignum-digit (math-xor-bignum (math-norm-bignum (car qa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381 (math-norm-bignum (car qb)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 (logxor (cdr qa) (cdr qb)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
386 (defun calcFunc-diff (a b &optional w) ; [I I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
387 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
388 (calcFunc-diff a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
389 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
390 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
391 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
392 (math-clip (logand a (lognot b)) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
393 ((or (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
394 (math-binary-modulo-args 'calcFunc-diff a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
397 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
398 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
399 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400 (math-diff-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
401 (math-binary-arg b w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
402 w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
403 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
404
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
405 (defun math-diff-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406 (and a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407 (let ((qa (math-div-bignum-digit a 512))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 (qb (math-div-bignum-digit b 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409 (math-mul-bignum-digit (math-diff-bignum (math-norm-bignum (car qa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 (math-norm-bignum (car qb)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412 (logand (cdr qa) (lognot (cdr qb))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
413 )
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 (defun calcFunc-not (a &optional w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417 (calcFunc-not a (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418 ((eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
419 (math-binary-modulo-args 'calcFunc-not a nil w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
421 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
422 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
423 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
424 ((< (or w (setq w calc-word-size)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
425 (math-clip (calcFunc-not a (- w)) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
426 (t (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
427 (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
428 (math-not-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
429 w)))))
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
432 (defun math-not-bignum (a w) ; [l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (let ((q (math-div-bignum-digit a 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 (if (<= w 9)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 (list (logand (lognot (cdr q))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 (1- (lsh 1 w))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (math-mul-bignum-digit (math-not-bignum (math-norm-bignum (car q))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
438 (- w 9))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439 512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 (logxor (cdr q) 511))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 (defun calcFunc-lsh (a &optional n w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 (setq a (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445 n (if n (math-trunc n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447 (math-binary-modulo-args 'calcFunc-lsh a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (setq w (if w (math-trunc w) calc-word-size))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (or (integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 (or (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
453 (or (Math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
454 (math-reject-arg n 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
455 (if (< w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 (math-clip (calcFunc-lsh a n (- w)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
457 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
458 (setq a (math-clip a w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459 (cond ((or (Math-lessp n (- w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
460 (Math-lessp w n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462 ((< n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 (math-quotient (math-clip a w) (math-power-of-2 (- n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (math-clip (math-mul a (math-power-of-2 n)) w)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
468 (defun calcFunc-rsh (a &optional n w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
469 (calcFunc-lsh a (math-neg (or n 1)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
470 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
472 (defun calcFunc-ash (a &optional n w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
473 (if (or (null n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474 (not (Math-negp n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475 (calcFunc-lsh a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476 (setq a (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 n (if n (math-trunc n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
478 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
479 (math-binary-modulo-args 'calcFunc-ash a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 (setq w (if w (math-trunc w) calc-word-size))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
481 (or (integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
482 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
483 (or (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
484 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
485 (or (Math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
486 (math-reject-arg n 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
487 (if (< w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488 (math-clip (calcFunc-ash a n (- w)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
489 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
490 (setq a (math-clip a w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
491 (let ((two-to-sizem1 (math-power-of-2 (1- w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
492 (sh (calcFunc-lsh a n w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
493 (cond ((Math-natnum-lessp a two-to-sizem1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
494 sh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495 ((Math-lessp n (- 1 w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 (math-add (math-mul two-to-sizem1 2) -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 (t (let ((two-to-n (math-power-of-2 (- n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
498 (math-add (calcFunc-lsh (math-add two-to-n -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (+ w n) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 sh))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
502
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503 (defun calcFunc-rash (a &optional n w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
504 (calcFunc-ash a (math-neg (or n 1)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
505 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (defun calcFunc-rot (a &optional n w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
508 (setq a (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
509 n (if n (math-trunc n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 (math-binary-modulo-args 'calcFunc-rot a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
512 (setq w (if w (math-trunc w) calc-word-size))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (or (integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
514 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515 (or (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 (or (Math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518 (math-reject-arg n 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (if (< w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
520 (math-clip (calcFunc-rot a n (- w)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
521 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 (setq a (math-clip a w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (cond ((or (Math-integer-negp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 (not (Math-natnum-lessp n w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (calcFunc-rot a (math-mod n w) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
527 (math-add (calcFunc-lsh a (- n w) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
528 (calcFunc-lsh a n w))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
531 (defun math-clip (a &optional w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 (math-clip a (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 ((eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 (math-binary-modulo-args 'math-clip a nil w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
539 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
540 ((< (or w (setq w calc-word-size)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
541 (setq a (math-clip a (- w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 (if (Math-natnum-lessp a (math-power-of-2 (- -1 w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
544 (math-sub a (math-power-of-2 (- w)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545 ((Math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 (math-normalize (cons 'bigpos (math-binary-arg a w))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547 ((and (integerp a) (< a 1000000))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
548 (if (>= w 20)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
549 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
550 (logand a (1- (lsh 1 w)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
551 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
552 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
553 (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
554 (math-clip-bignum (cdr (math-bignum-test (math-trunc a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 w)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
556 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
557 (fset 'calcFunc-clip (symbol-function 'math-clip))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
558
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 (defun math-clip-bignum (a w) ; [l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 (let ((q (math-div-bignum-digit a 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
561 (if (<= w 9)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 (list (logand (cdr q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
563 (1- (lsh 1 w))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 (math-mul-bignum-digit (math-clip-bignum (math-norm-bignum (car q))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565 (- w 9))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (cdr q))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
568 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
570
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
571
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 (defvar math-max-digits-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
574 (defun math-compute-max-digits (w r)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (let* ((pair (+ (* r 100000) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 (res (assq pair math-max-digits-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (cdr res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
579 (let* ((calc-command-flags nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580 (digs (math-ceiling (math-div w (math-real-log2 r)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (setq math-max-digits-cache (cons (cons pair digs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
582 math-max-digits-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
583 digs)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
584 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
585
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586 (defvar math-log2-cache (list '(2 . 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
587 '(4 . 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
588 '(8 . 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589 '(10 . (float 332193 -5))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 '(16 . 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 '(32 . 5)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
592 (defun math-real-log2 (x) ;;; calc-internal-prec must be 6
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 (let ((res (assq x math-log2-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
594 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 (cdr res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
596 (let* ((calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
597 (calc-display-working-message nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
598 (log (calcFunc-log x 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599 (setq math-log2-cache (cons (cons x log) math-log2-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 log)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 (defconst math-radix-digits ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
604 "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
605 "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606 "U" "V" "W" "X" "Y" "Z"])
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
608 (defun math-format-radix (a) ; [X S]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
609 (if (< a calc-number-radix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
610 (if (< a 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
611 (concat "-" (math-format-radix (- a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
612 (math-format-radix-digit a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613 (let ((s ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
614 (while (> a 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
615 (setq s (concat (math-format-radix-digit (% a calc-number-radix)) s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
616 a (/ a calc-number-radix)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
617 s))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
618 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
619
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
620 (defconst math-binary-digits ["000" "001" "010" "011"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
621 "100" "101" "110" "111"])
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
622 (defun math-format-binary (a) ; [X S]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
623 (if (< a 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
624 (if (< a 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
625 (concat "-" (math-format-binary (- a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
626 (math-format-radix a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627 (let ((s ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 (while (> a 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
629 (setq s (concat (aref math-binary-digits (% a 8)) s)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630 a (/ a 8)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 (concat (math-format-radix a) s)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
632 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
633
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
634 (defun math-format-bignum-radix (a) ; [X L]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 (cond ((null a) "0")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
636 ((and (null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 (< (car a) calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 (math-format-radix-digit (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 (let ((q (math-div-bignum-digit a calc-number-radix)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
641 (concat (math-format-bignum-radix (math-norm-bignum (car q)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (math-format-radix-digit (cdr q))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
644
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
645 (defun math-format-bignum-binary (a) ; [X L]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
646 (cond ((null a) "0")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
647 ((null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648 (math-format-binary (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
650 (let ((q (math-div-bignum-digit a 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 (concat (math-format-bignum-binary (math-norm-bignum (car q)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
652 (aref math-binary-digits (/ (cdr q) 64))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
653 (aref math-binary-digits (% (/ (cdr q) 8) 8))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
654 (aref math-binary-digits (% (cdr q) 8))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
655 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
656
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
657 (defun math-format-bignum-octal (a) ; [X L]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
658 (cond ((null a) "0")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 ((null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
660 (math-format-radix (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 (let ((q (math-div-bignum-digit a 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 (concat (math-format-bignum-octal (math-norm-bignum (car q)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 (math-format-radix-digit (/ (cdr q) 64))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (math-format-radix-digit (% (/ (cdr q) 8) 8))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
666 (math-format-radix-digit (% (cdr q) 8))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
667 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
668
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
669 (defun math-format-bignum-hex (a) ; [X L]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670 (cond ((null a) "0")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
671 ((null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 (math-format-radix (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
673 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
674 (let ((q (math-div-bignum-digit a 256)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
675 (concat (math-format-bignum-hex (math-norm-bignum (car q)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
676 (math-format-radix-digit (/ (cdr q) 16))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 (math-format-radix-digit (% (cdr q) 16))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
678 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 ;;; Decompose into integer and fractional parts, without depending
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 ;;; on calc-internal-prec.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 (defun math-float-parts (a need-frac) ; returns ( int frac fracdigs )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 (if (>= (nth 2 a) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
684 (list (math-scale-rounding (nth 1 a) (nth 2 a)) '(float 0 0) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
685 (let* ((d (math-numdigs (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
686 (n (- (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
687 (if need-frac
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (if (>= n d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (list 0 a n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
690 (let ((qr (math-idivmod (nth 1 a) (math-scale-int 1 n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
691 (list (car qr) (math-make-float (cdr qr) (- n)) n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
692 (list (math-scale-rounding (nth 1 a) (nth 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
693 '(float 0 0) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
694 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
695
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
696 (defun math-format-radix-float (a prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
697 (let ((fmt (car calc-float-format))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (figs (nth 1 calc-float-format))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (point calc-point-char)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (str nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
701 (if (eq fmt 'fix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
702 (let* ((afigs (math-abs figs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (fp (math-float-parts a (> afigs 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 (calc-internal-prec (+ 3 (max (nth 2 fp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
705 (math-convert-radix-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
706 afigs t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
707 (int (car fp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
708 (frac (math-round (math-mul (math-normalize (nth 1 fp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 (math-radix-float-power afigs)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
710 (if (not (and (math-zerop frac) (math-zerop int) (< figs 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711 (let ((math-radix-explicit-format nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
712 (let ((calc-group-digits nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
713 (setq str (if (> afigs 0) (math-format-number frac) ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
714 (if (< (length str) afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
715 (setq str (concat (make-string (- afigs (length str)) ?0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
716 str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
717 (if (> (length str) afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
718 (setq str (substring str 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
719 int (math-add int 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
720 (setq str (concat (math-format-number int) point str)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
721 (if calc-group-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
722 (setq str (math-group-float str))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
723 (setq figs 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
724 (or str
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725 (let* ((prec calc-internal-prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
726 (afigs (if (> figs 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
727 figs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
728 (max 1 (+ figs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
729 (1- (math-convert-radix-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
730 (max prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
731 (math-numdigs (nth 1 a)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
732 (calc-internal-prec (+ 3 (math-convert-radix-digits afigs t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
733 (explo -1) (vlo (math-radix-float-power explo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
734 (exphi 1) (vhi (math-radix-float-power exphi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
735 expmid vmid eadj)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
736 (setq a (math-normalize a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
737 (if (Math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
738 (setq explo 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
739 (if (math-lessp-float '(float 1 0) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
740 (while (not (math-lessp-float a vhi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
741 (setq explo exphi vlo vhi
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
742 exphi (math-mul exphi 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
743 vhi (math-radix-float-power exphi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
744 (while (math-lessp-float a vlo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
745 (setq exphi explo vhi vlo
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
746 explo (math-mul explo 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
747 vlo (math-radix-float-power explo))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
748 (while (not (eq (math-sub exphi explo) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
749 (setq expmid (math-div2 (math-add explo exphi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
750 vmid (math-radix-float-power expmid))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
751 (if (math-lessp-float a vmid)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
752 (setq exphi expmid vhi vmid)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
753 (setq explo expmid vlo vmid)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
754 (setq a (math-div-float a vlo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
755 (let* ((sc (math-round (math-mul a (math-radix-float-power
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
756 (1- afigs)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
757 (math-radix-explicit-format nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
758 (let ((calc-group-digits nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
759 (setq str (math-format-number sc))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
760 (if (> (length str) afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
761 (setq str (substring str 0 -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
762 explo (1+ explo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
763 (if (and (eq fmt 'float)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
764 (math-lessp explo (+ (if (= figs 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
765 (1- (math-convert-radix-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
766 prec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
767 afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
768 calc-display-sci-high 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
769 (math-lessp calc-display-sci-low explo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
770 (let ((dpos (1+ explo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
771 (cond ((<= dpos 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
772 (setq str (concat "0" point (make-string (- dpos) ?0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
773 str)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
774 ((> dpos (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
775 (setq str (concat str (make-string (- dpos (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
776 ?0) point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
777 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
778 (setq str (concat (substring str 0 dpos) point
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
779 (substring str dpos)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
780 (setq explo nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
781 (setq eadj (if (eq fmt 'eng)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
782 (min (math-mod explo 3) (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
783 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
784 str (concat (substring str 0 (1+ eadj)) point
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
785 (substring str (1+ eadj)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
786 (setq pos (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
787 (while (eq (aref str (1- pos)) ?0) (setq pos (1- pos)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
788 (and explo (eq (aref str (1- pos)) ?.) (setq pos (1- pos)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
789 (setq str (substring str 0 pos))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
790 (if calc-group-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
791 (setq str (math-group-float str)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
792 (if explo
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
793 (let ((estr (let ((calc-number-radix 10)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
794 (calc-group-digits nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
795 (setq estr (math-format-number
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
796 (math-sub explo eadj))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
797 (setq str (if (or (memq calc-language '(math maple))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
798 (> calc-number-radix 14))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
799 (format "%s*%d.^%s" str calc-number-radix estr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
800 (format "%se%s" str estr)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
801 str)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
803
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
804 (defun math-convert-radix-digits (n &optional to-dec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
805 (let ((key (cons n (cons to-dec calc-number-radix))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
806 (or (cdr (assoc key math-radix-digits-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
807 (let* ((calc-internal-prec 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
808 (log (math-div (math-real-log2 calc-number-radix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
809 '(float 332193 -5))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
810 (cdr (car (setq math-radix-digits-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
811 (cons (cons key (math-ceiling (if to-dec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
812 (math-mul n log)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
813 (math-div n log))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
814 math-radix-digits-cache)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
815 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
816 (setq math-radix-digits-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
817
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
818 (defun math-radix-float-power (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
819 (if (eq n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
820 '(float 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
821 (or (and (eq calc-number-radix (car math-radix-float-cache-tag))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
822 (<= calc-internal-prec (cdr math-radix-float-cache-tag)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
823 (setq math-radix-float-cache-tag (cons calc-number-radix
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
824 calc-internal-prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
825 math-radix-float-cache nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
826 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
827 (or (cdr (assoc n math-radix-float-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
828 (cdr (car (setq math-radix-float-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
829 (cons (cons
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
830 n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
831 (let ((calc-internal-prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
832 (cdr math-radix-float-cache-tag)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
833 (if (math-negp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
834 (math-div-float '(float 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
835 (math-radix-float-power
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
836 (math-neg n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
837 (math-mul-float (math-sqr-float
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
838 (math-radix-float-power
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
839 (math-div2 n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
840 (if (math-evenp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
841 '(float 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
842 (math-float
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
843 calc-number-radix))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
844 math-radix-float-cache)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
845 )
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
846 (setq math-radix-float-cache-tag nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
847