annotate lisp/calc/calc-bin.el @ 112425:9f7614f1a892

Merge from emacs-23
author Glenn Morris <rgm@gnu.org>
date Sat, 22 Jan 2011 11:36:45 -0800
parents ef719132ddfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
1 ;;; calc-bin.el --- binary functions for Calc
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
2
64325
1db49616ce05 Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62033
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
5
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
6 ;; Author: David Gillespie <daveg@synaptics.com>
77465
1154f082efd9 Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 76595
diff changeset
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
19 ;; GNU General Public License for more details.
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
20
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
24 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
26 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; This file is autoloaded from calc-ext.el.
58648
617cbf064b4b Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58553
diff changeset
29
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
33 ;;; Some useful numbers
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
34 (defconst math-bignum-logb-digit-size
82439
d45f82f9c8f3 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
35 (logb math-bignum-digit-size)
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
36 "The logb of the size of a bignum digit.
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
37 This is the largest value of B such that 2^B is less than
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
38 the size of a Calc bignum digit.")
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
39
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
40 (defconst math-bignum-digit-power-of-two
82439
d45f82f9c8f3 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 82140
diff changeset
41 (expt 2 (logb math-bignum-digit-size))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
42 "The largest power of 2 less than the size of a Calc bignum digit.")
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
43
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 ;;; b-prefix binary commands.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (defun calc-and (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 (calc-enter-result 2 "and"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50 (append '(calcFunc-and)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 (calc-top-list-n 2)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
52 (and n (list (prefix-numeric-value n)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (defun calc-or (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
56 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57 (calc-enter-result 2 "or"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (append '(calcFunc-or)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (calc-top-list-n 2)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
60 (and n (list (prefix-numeric-value n)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 (defun calc-xor (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (calc-enter-result 2 "xor"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (append '(calcFunc-xor)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (calc-top-list-n 2)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
68 (and n (list (prefix-numeric-value n)))))))
40785
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-diff (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 2 "diff"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (append '(calcFunc-diff)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 (calc-top-list-n 2)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
76 (and n (list (prefix-numeric-value n)))))))
40785
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 (defun calc-not (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 (calc-enter-result 1 "not"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (append '(calcFunc-not)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (calc-top-list-n 1)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
84 (and n (list (prefix-numeric-value n)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 (defun calc-lshift-binary (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 (calc-enter-result hyp "lsh"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91 (append '(calcFunc-lsh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (calc-top-list-n hyp)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
93 (and n (list (prefix-numeric-value n))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (defun calc-rshift-binary (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (calc-enter-result hyp "rsh"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (append '(calcFunc-rsh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101 (calc-top-list-n hyp)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
102 (and n (list (prefix-numeric-value n))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (defun calc-lshift-arith (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
105 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108 (calc-enter-result hyp "ash"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (append '(calcFunc-ash)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110 (calc-top-list-n hyp)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
111 (and n (list (prefix-numeric-value n))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
112
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
113 (defun calc-rshift-arith (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 (calc-enter-result hyp "rash"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 (append '(calcFunc-rash)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 (calc-top-list-n hyp)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
120 (and n (list (prefix-numeric-value n))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (defun calc-rotate-binary (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (let ((hyp (if (calc-is-hyperbolic) 2 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (calc-enter-result hyp "rot"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 (append '(calcFunc-rot)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (calc-top-list-n hyp)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
129 (and n (list (prefix-numeric-value n))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (defun calc-clip (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (calc-enter-result 1 "clip"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 (append '(calcFunc-clip)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 (calc-top-list-n 1)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
137 (and n (list (prefix-numeric-value n)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (defun calc-word-size (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (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
143 calc-word-size))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (setq n (if (stringp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145 (if (equal n "")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 calc-word-size
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 (if (string-match "\\`[-+]?[0-9]+\\'" n)
62033
729b3756f347 (calc-word-size): Replace string-to-int by string-to-number.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58648
diff changeset
148 (string-to-number n)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (error "Expected an integer")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (prefix-numeric-value n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (or (= n calc-word-size)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152 (if (> (math-abs n) 100)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 (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
154 (calc-change-mode '(calc-word-size calc-previous-modulo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 (list n (math-power-of-2 (math-abs n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
156 calc-leading-zeros)))
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
157 (setq math-2-word-size (math-power-of-2 (math-abs n)))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
158 (setq math-half-2-word-size (math-power-of-2 (1- (math-abs n))))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
159 (calc-do-refresh)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
160 (calc-refresh-evaltos)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
161 (if (< n 0)
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
162 (message "Binary word size is %d bits (two's complement)" (- n))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
163 (message "Binary word size is %d bits" n))))
40785
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
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
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
168
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
169 ;;; d-prefix mode commands.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
171 (defun calc-radix (n &optional arg)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172 (interactive "NDisplay radix (2-36): ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
173 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174 (if (and (>= n 2) (<= n 36))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (progn
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
176 (calc-change-mode
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
177 (list 'calc-number-radix 'calc-twos-complement-mode)
107890
b2e098d47dff calc-bin.el (calc-radix): Have the O option turn on twos-complement mode.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106815
diff changeset
178 (list n (or arg (calc-is-option))) t)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 ;; also change global value so minibuffer sees it
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (setq-default calc-number-radix calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (setq n calc-number-radix))
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
182 (if calc-twos-complement-mode
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
183 (message "Number radix is %d, two's complement mode is on." n)
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
184 (message "Number radix is %d" n))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 (defun calc-decimal-radix ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 (interactive)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
188 (calc-radix 10))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
190 (defun calc-binary-radix (&optional arg)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
191 (interactive "P")
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
192 (calc-radix 2 arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
194 (defun calc-octal-radix (&optional arg)
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
195 (interactive "P")
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
196 (calc-radix 8 arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
198 (defun calc-hex-radix (&optional arg)
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
199 (interactive "P")
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
200 (calc-radix 16 arg))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
201
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 (defun calc-leading-zeros (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 (calc-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 (if (calc-change-mode 'calc-leading-zeros n t t)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
206 (message "Zero-padding integers to %d digits (assuming radix %d)"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 (let* ((calc-internal-prec 6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 (math-compute-max-digits (math-abs calc-word-size)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210 calc-number-radix)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
211 (message "Omitting leading zeros on integers"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
213
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214 (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
215 (defvar math-big-power-of-2-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
216 (defun math-power-of-2 (n) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (if (and (natnump n) (<= n 100))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
218 (or (nth n math-power-of-2-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219 (let* ((i (length math-power-of-2-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220 (val (nth (1- i) math-power-of-2-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221 (while (<= i n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 (setq val (math-mul val 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 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
224 (list val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 i (1+ i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
226 val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
227 (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
228 (if found
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
229 (cdr found)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230 (let ((po2 (math-ipow 2 n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231 (setq math-big-power-of-2-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
232 (cons (cons n po2) math-big-power-of-2-cache))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
233 po2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
234
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
235 (defun math-integer-log2 (n) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
236 (let ((i 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
237 (p math-power-of-2-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
238 val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
239 (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
240 (setq p (cdr p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
241 i (1+ i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
242 (if p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
243 (and (equal val n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
244 i)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
245 (while (Math-natnum-lessp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
246 (prog1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
247 (setq val (math-mul val 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
248 (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
249 (list val))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
250 n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251 (setq i (1+ i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 (and (equal val n)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
253 i))))
40785
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)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
276 w))))
40785
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 (defun math-binary-arg (a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 (if (not (Math-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 (setq a (math-trunc a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 (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
283 (math-abs (if w (math-trunc w) calc-word-size)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
284 (cdr (Math-bignum-test a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 (defun math-binary-modulo-args (f a b w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 (let (mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 (setq mod (nth 2 a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 a (nth 1 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (if (eq (car-safe b) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 (if (equal mod (nth 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (setq b (nth 1 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (math-reject-arg b "*Inconsistent modulos"))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (setq mod (nth 2 b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 b (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (if (Math-messy-integerp mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 (setq mod (math-trunc mod))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 (or (Math-integerp mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301 (math-reject-arg mod 'integerp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (let ((bits (math-integer-log2 mod)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (if bits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (if w
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 (if (/= w bits)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (calc-record-why
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 "*Warning: Modulo inconsistent with word size"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (setq w bits))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 (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
310 (math-make-mod (if b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 (funcall f a b w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 (funcall f a w))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
313 mod))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 (defun math-and-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 (and a b
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
317 (let ((qa (math-div-bignum-digit a math-bignum-digit-power-of-two))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
318 (qb (math-div-bignum-digit b math-bignum-digit-power-of-two)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 (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
320 (math-norm-bignum (car qb)))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
321 math-bignum-digit-power-of-two
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
322 (logand (cdr qa) (cdr qb))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 (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
325 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 (calcFunc-or a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
329 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
330 (math-clip (logior a b) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
331 ((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
332 (math-binary-modulo-args 'calcFunc-or a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
337 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338 (math-or-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
339 (math-binary-arg b w)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
340 w))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 (defun math-or-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (and (or a b)
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
344 (let ((qa (math-div-bignum-digit a math-bignum-digit-power-of-two))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
345 (qb (math-div-bignum-digit b math-bignum-digit-power-of-two)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346 (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
347 (math-norm-bignum (car qb)))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
348 math-bignum-digit-power-of-two
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
349 (logior (cdr qa) (cdr qb))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
350
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351 (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
352 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 (calcFunc-xor a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 (math-clip (logxor a b) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
358 ((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
359 (math-binary-modulo-args 'calcFunc-xor a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
363 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
365 (math-xor-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 (math-binary-arg b w)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
367 w))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 (defun math-xor-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370 (and (or a b)
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
371 (let ((qa (math-div-bignum-digit a math-bignum-digit-power-of-two))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
372 (qb (math-div-bignum-digit b math-bignum-digit-power-of-two)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373 (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
374 (math-norm-bignum (car qb)))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
375 math-bignum-digit-power-of-two
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
376 (logxor (cdr qa) (cdr qb))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
377
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
378 (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
379 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 (calcFunc-diff a b (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 ((and (integerp a) (integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384 (math-clip (logand a (lognot b)) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385 ((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
386 (math-binary-modulo-args 'calcFunc-diff a b w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
387 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
388 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
389 ((not (Math-num-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
390 (math-reject-arg b 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
391 (t (math-clip (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
392 (math-diff-bignum (math-binary-arg a w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
393 (math-binary-arg b w)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
394 w))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 (defun math-diff-bignum (a b) ; [l l l]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
397 (and a
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
398 (let ((qa (math-div-bignum-digit a math-bignum-digit-power-of-two))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
399 (qb (math-div-bignum-digit b math-bignum-digit-power-of-two)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400 (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
401 (math-norm-bignum (car qb)))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
402 math-bignum-digit-power-of-two
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
403 (logand (cdr qa) (lognot (cdr qb)))))))
40785
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 calcFunc-not (a &optional w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407 (calcFunc-not a (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 ((eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409 (math-binary-modulo-args 'calcFunc-not a nil w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
413 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414 ((< (or w (setq w calc-word-size)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
415 (math-clip (calcFunc-not a (- w)) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 (t (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417 (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418 (math-not-bignum (math-binary-arg a w)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
419 w))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
421 (defun math-not-bignum (a w) ; [l l]
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
422 (let ((q (math-div-bignum-digit a math-bignum-digit-power-of-two)))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
423 (if (<= w math-bignum-logb-digit-size)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
424 (list (logand (lognot (cdr q))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
425 (1- (lsh 1 w))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
426 (math-mul-bignum-digit (math-not-bignum (math-norm-bignum (car q))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
427 (- w math-bignum-logb-digit-size))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
428 math-bignum-digit-power-of-two
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
429 (logxor (cdr q)
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
430 (1- math-bignum-digit-power-of-two))))))
40785
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 calcFunc-lsh (a &optional n w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (setq a (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 n (if n (math-trunc n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 (math-binary-modulo-args 'calcFunc-lsh a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (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
438 (or (integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 (or (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442 (or (Math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 (math-reject-arg n 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 (if (< w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445 (math-clip (calcFunc-lsh a n (- w)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447 (setq a (math-clip a w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (cond ((or (Math-lessp n (- w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (Math-lessp w n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 ((< n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 (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
453 (t
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
454 (math-clip (math-mul a (math-power-of-2 n)) w))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
455
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 (defun calcFunc-rsh (a &optional n w) ; [I I] [Public]
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
457 (calcFunc-lsh a (math-neg (or n 1)) w))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
458
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459 (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
460 (if (or (null n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (not (Math-negp n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462 (calcFunc-lsh a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 (setq a (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 n (if n (math-trunc n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466 (math-binary-modulo-args 'calcFunc-ash a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467 (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
468 (or (integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
469 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
470 (or (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
472 (or (Math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
473 (math-reject-arg n 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474 (if (< w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475 (math-clip (calcFunc-ash a n (- w)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 (setq a (math-clip a w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
478 (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
479 (sh (calcFunc-lsh a n w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 (cond ((Math-natnum-lessp a two-to-sizem1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
481 sh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
482 ((Math-lessp n (- 1 w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
483 (math-add (math-mul two-to-sizem1 2) -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
484 (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
485 (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
486 (+ w n) w)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
487 sh)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
489 (defun calcFunc-rash (a &optional n w) ; [I I] [Public]
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
490 (calcFunc-ash a (math-neg (or n 1)) w))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
491
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
492 (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
493 (setq a (math-trunc a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
494 n (if n (math-trunc n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495 (if (eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 (math-binary-modulo-args 'calcFunc-rot a n w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 (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
498 (or (integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 (or (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
502 (or (Math-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503 (math-reject-arg n 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
504 (if (< w 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
505 (math-clip (calcFunc-rot a n (- w)) w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506 (if (Math-integer-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (setq a (math-clip a w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
508 (cond ((or (Math-integer-negp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
509 (not (Math-natnum-lessp n w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 (calcFunc-rot a (math-mod n w) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
512 (math-add (calcFunc-lsh a (- n w) w)
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
513 (calcFunc-lsh a n w)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
514
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515 (defun math-clip (a &optional w) ; [I I] [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516 (cond ((Math-messy-integerp w)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 (math-clip a (math-trunc w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518 ((eq (car-safe a) 'mod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (math-binary-modulo-args 'math-clip a nil w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
520 ((and w (not (integerp w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
521 (math-reject-arg w 'fixnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 ((not (Math-num-integerp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (math-reject-arg a 'integerp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 ((< (or w (setq w calc-word-size)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (setq a (math-clip a (- w)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (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
527 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
528 (math-sub a (math-power-of-2 (- w)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 ((Math-negp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 (math-normalize (cons 'bigpos (math-binary-arg a w))))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
531 ((and (integerp a) (< a math-small-integer-size))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
532 (if (> w (logb math-small-integer-size))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 (logand a (1- (lsh 1 w)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (cons 'bigpos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 (math-clip-bignum (cdr (math-bignum-test (math-trunc a)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
539 w))))))
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
540
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
541 (defalias 'calcFunc-clip 'math-clip)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 (defun math-clip-bignum (a w) ; [l l]
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
544 (let ((q (math-div-bignum-digit a math-bignum-digit-power-of-two)))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
545 (if (<= w math-bignum-logb-digit-size)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 (list (logand (cdr q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547 (1- (lsh 1 w))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
548 (math-mul-bignum-digit (math-clip-bignum (math-norm-bignum (car q))
81717
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
549 (- w math-bignum-logb-digit-size))
f81d25630552 (math-bignum-logb-digit-size,math-bignum-digit-power-of-two): New
Jay Belanger <jay.p.belanger@gmail.com>
parents: 77465
diff changeset
550 math-bignum-digit-power-of-two
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
551 (cdr q)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
552
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
553 (defvar math-max-digits-cache nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
554 (defun math-compute-max-digits (w r)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 (let* ((pair (+ (* r 100000) w))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
556 (res (assq pair math-max-digits-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
557 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
558 (cdr res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 (let* ((calc-command-flags nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 (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
561 (setq math-max-digits-cache (cons (cons pair digs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 math-max-digits-cache))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
563 digs))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565 (defvar math-log2-cache (list '(2 . 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 '(4 . 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 '(8 . 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
568 '(10 . (float 332193 -5))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569 '(16 . 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
570 '(32 . 5)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
571 (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
572 (let ((res (assq x math-log2-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
574 (cdr res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (let* ((calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 (calc-display-working-message nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 (log (calcFunc-log x 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (setq math-log2-cache (cons (cons x log) math-log2-cache))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
579 log))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (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
582 "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
583 "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
584 "U" "V" "W" "X" "Y" "Z"])
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
585
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
586 (defsubst math-format-radix-digit (a) ; [X D]
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
587 (aref math-radix-digits a))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
588
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589 (defun math-format-radix (a) ; [X S]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 (if (< a calc-number-radix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 (if (< a 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
592 (concat "-" (math-format-radix (- a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 (math-format-radix-digit a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
594 (let ((s ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 (while (> a 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
596 (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
597 a (/ a calc-number-radix)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
598 s)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 (defconst math-binary-digits ["000" "001" "010" "011"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 "100" "101" "110" "111"])
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602 (defun math-format-binary (a) ; [X S]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 (if (< a 8)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
604 (if (< a 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
605 (concat "-" (math-format-binary (- a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606 (math-format-radix a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607 (let ((s ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
608 (while (> a 7)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
609 (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
610 a (/ a 8)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
611 (concat (math-format-radix a) s))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
612
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613 (defun math-format-bignum-radix (a) ; [X L]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
614 (cond ((null a) "0")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
615 ((and (null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
616 (< (car a) calc-number-radix))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
617 (math-format-radix-digit (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
618 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
619 (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
620 (concat (math-format-bignum-radix (math-norm-bignum (car q)))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
621 (math-format-radix-digit (cdr q)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
622
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
623 (defun math-format-bignum-binary (a) ; [X L]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
624 (cond ((null a) "0")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
625 ((null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
626 (math-format-binary (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 (let ((q (math-div-bignum-digit a 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
629 (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
630 (aref math-binary-digits (/ (cdr q) 64))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 (aref math-binary-digits (% (/ (cdr q) 8) 8))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
632 (aref math-binary-digits (% (cdr q) 8)))))))
40785
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-octal (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 ((null (cdr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 (math-format-radix (car a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 (let ((q (math-div-bignum-digit a 512)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 (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
641 (math-format-radix-digit (/ (cdr q) 64))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (math-format-radix-digit (% (/ (cdr q) 8) 8))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
643 (math-format-radix-digit (% (cdr q) 8)))))))
40785
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-hex (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-radix (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 256)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 (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
652 (math-format-radix-digit (/ (cdr q) 16))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
653 (math-format-radix-digit (% (cdr q) 16)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
654
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
655 ;;; Decompose into integer and fractional parts, without depending
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
656 ;;; on calc-internal-prec.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
657 (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
658 (if (>= (nth 2 a) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 (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
660 (let* ((d (math-numdigs (nth 1 a)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 (n (- (nth 2 a))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 (if need-frac
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 (if (>= n d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 (list 0 a n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (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
666 (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
667 (list (math-scale-rounding (nth 1 a) (nth 2 a))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
668 '(float 0 0) 0)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
669
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670 (defun math-format-radix-float (a prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
671 (let ((fmt (car calc-float-format))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 (figs (nth 1 calc-float-format))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
673 (point calc-point-char)
58553
1c7dfa5d5967 (math-format-radix-float): Make pos a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
674 (str nil)
1c7dfa5d5967 (math-format-radix-float): Make pos a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
675 pos)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
676 (if (eq fmt 'fix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 (let* ((afigs (math-abs figs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
678 (fp (math-float-parts a (> afigs 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679 (calc-internal-prec (+ 3 (max (nth 2 fp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 (math-convert-radix-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 afigs t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 (int (car fp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 (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
684 (math-radix-float-power afigs)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
685 (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
686 (let ((math-radix-explicit-format nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
687 (let ((calc-group-digits nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (setq str (if (> afigs 0) (math-format-number frac) ""))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (if (< (length str) afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
690 (setq str (concat (make-string (- afigs (length str)) ?0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
691 str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
692 (if (> (length str) afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
693 (setq str (substring str 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
694 int (math-add int 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
695 (setq str (concat (math-format-number int) point str)))
44572
9e404d7dbe1d (math-format-radix-float): Load `calc-ext' before we call `math-group-float'.
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
696 (when calc-group-digits
9e404d7dbe1d (math-format-radix-float): Load `calc-ext' before we call `math-group-float'.
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
697 (setq str (math-group-float str))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (setq figs 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (or str
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (let* ((prec calc-internal-prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
701 (afigs (if (> figs 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
702 figs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (max 1 (+ figs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 (1- (math-convert-radix-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
705 (max prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
706 (math-numdigs (nth 1 a)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
707 (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
708 (explo -1) (vlo (math-radix-float-power explo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 (exphi 1) (vhi (math-radix-float-power exphi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
710 expmid vmid eadj)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711 (setq a (math-normalize a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
712 (if (Math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
713 (setq explo 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
714 (if (math-lessp-float '(float 1 0) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
715 (while (not (math-lessp-float a vhi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
716 (setq explo exphi vlo vhi
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
717 exphi (math-mul exphi 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
718 vhi (math-radix-float-power exphi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
719 (while (math-lessp-float a vlo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
720 (setq exphi explo vhi vlo
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
721 explo (math-mul explo 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
722 vlo (math-radix-float-power explo))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
723 (while (not (eq (math-sub exphi explo) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
724 (setq expmid (math-div2 (math-add explo exphi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725 vmid (math-radix-float-power expmid))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
726 (if (math-lessp-float a vmid)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
727 (setq exphi expmid vhi vmid)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
728 (setq explo expmid vlo vmid)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
729 (setq a (math-div-float a vlo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
730 (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
731 (1- afigs)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
732 (math-radix-explicit-format nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
733 (let ((calc-group-digits nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
734 (setq str (math-format-number sc))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
735 (if (> (length str) afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
736 (setq str (substring str 0 -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
737 explo (1+ explo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
738 (if (and (eq fmt 'float)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
739 (math-lessp explo (+ (if (= figs 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
740 (1- (math-convert-radix-digits
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
741 prec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
742 afigs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
743 calc-display-sci-high 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
744 (math-lessp calc-display-sci-low explo))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
745 (let ((dpos (1+ explo)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
746 (cond ((<= dpos 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
747 (setq str (concat "0" point (make-string (- dpos) ?0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
748 str)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
749 ((> dpos (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
750 (setq str (concat str (make-string (- dpos (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
751 ?0) point)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
752 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
753 (setq str (concat (substring str 0 dpos) point
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
754 (substring str dpos)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
755 (setq explo nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
756 (setq eadj (if (eq fmt 'eng)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
757 (min (math-mod explo 3) (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
758 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
759 str (concat (substring str 0 (1+ eadj)) point
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
760 (substring str (1+ eadj)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
761 (setq pos (length str))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
762 (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
763 (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
764 (setq str (substring str 0 pos))
44572
9e404d7dbe1d (math-format-radix-float): Load `calc-ext' before we call `math-group-float'.
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
765 (when calc-group-digits
9e404d7dbe1d (math-format-radix-float): Load `calc-ext' before we call `math-group-float'.
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
766 (setq str (math-group-float str)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
767 (if explo
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
768 (let ((estr (let ((calc-number-radix 10)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
769 (calc-group-digits nil))
58553
1c7dfa5d5967 (math-format-radix-float): Make pos a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
770 (math-format-number
1c7dfa5d5967 (math-format-radix-float): Make pos a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
771 (math-sub explo eadj)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
772 (setq str (if (or (memq calc-language '(math maple))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
773 (> calc-number-radix 14))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
774 (format "%s*%d.^%s" str calc-number-radix estr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
775 (format "%se%s" str estr)))))))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
776 str))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
777
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
778 (defvar math-radix-digits-cache nil)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
779
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
780 (defun math-convert-radix-digits (n &optional to-dec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
781 (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
782 (or (cdr (assoc key math-radix-digits-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
783 (let* ((calc-internal-prec 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
784 (log (math-div (math-real-log2 calc-number-radix)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
785 '(float 332193 -5))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
786 (cdr (car (setq math-radix-digits-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
787 (cons (cons key (math-ceiling (if to-dec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
788 (math-mul n log)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
789 (math-div n log))))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
790 math-radix-digits-cache))))))))
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
791
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41042
diff changeset
792 (defvar math-radix-float-cache-tag nil)
58553
1c7dfa5d5967 (math-format-radix-float): Make pos a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
793 (defvar math-radix-float-cache)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
794
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
795 (defun math-radix-float-power (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
796 (if (eq n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
797 '(float 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
798 (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
799 (<= calc-internal-prec (cdr math-radix-float-cache-tag)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
800 (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
801 calc-internal-prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802 math-radix-float-cache nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
803 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
804 (or (cdr (assoc n math-radix-float-cache))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
805 (cdr (car (setq math-radix-float-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
806 (cons (cons
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
807 n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
808 (let ((calc-internal-prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
809 (cdr math-radix-float-cache-tag)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
810 (if (math-negp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
811 (math-div-float '(float 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
812 (math-radix-float-power
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
813 (math-neg n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
814 (math-mul-float (math-sqr-float
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
815 (math-radix-float-power
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
816 (math-div2 n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
817 (if (math-evenp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
818 '(float 1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
819 (math-float
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
820 calc-number-radix))))))
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
821 math-radix-float-cache))))))))
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
822
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
823 ;;; Two's complement mode
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
824
106137
0e720bab47c6 (math-format-twos-complement): Renamed from math-format-complement-signed.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106068
diff changeset
825 (defun math-format-twos-complement (a)
106148
3875adeabec5 (calc-octal-radix, calc-hex-radix): Add spec.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 106137
diff changeset
826 "Format an integer in two's complement mode."
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
827 (let* (;(calc-leading-zeros t)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
828 (overflow nil)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
829 (negative nil)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
830 (num
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
831 (cond
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
832 ((or (eq a 0)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
833 (and (Math-integer-posp a)))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
834 (if (integerp a)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
835 (math-format-radix a)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
836 (math-format-bignum-radix (cdr a))))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
837 ((Math-integer-negp a)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
838 (let ((newa (math-add a math-2-word-size)))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
839 (if (integerp newa)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
840 (math-format-radix newa)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
841 (math-format-bignum-radix (cdr newa))))))))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
842 (let* ((calc-internal-prec 6)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
843 (digs (math-compute-max-digits (math-abs calc-word-size)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
844 calc-number-radix))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
845 (len (length num)))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
846 (if (< len digs)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
847 (setq num (concat (make-string (- digs len) ?0) num))))
108577
e81c7c754bb6 calc-bin.el (math-format-twos-complement): Group digits when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 107890
diff changeset
848 (when calc-group-digits
e81c7c754bb6 calc-bin.el (math-format-twos-complement): Group digits when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 107890
diff changeset
849 (setq num (math-group-float num)))
106038
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
850 (concat
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
851 (number-to-string calc-number-radix)
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
852 "##"
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
853 num)))
9ddf1eafde9a (calc-word-size): Reset the variables `math-2-word-size' and `math-half-2-word-size'.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
854
58648
617cbf064b4b Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58553
diff changeset
855 (provide 'calc-bin)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
856
41042
a78b609cb4b1 (calcFunc-clip): Use `defalias' instead of `fset' and
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
857 ;;; calc-bin.el ends here