1 ;;; number.el -- Enhanced Number Types for SXEmacs
3 ;; Copyright (C) 2005 by Sebastian Freundt
5 ;; Author: Sebastian Freundt <hroptatyr@sxemacs.org
6 ;; Created: Fri Nov 4 16:09:10 2005 UTC
7 ;; Keywords: lisp, number
9 ;; This file is part of SXEmacs.
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Synched up with: Not in FSF
27 ;; This file provides some additional functionality not worth
30 ;; Note to myself: number.el is a stupid name :(
33 (defun coprimep (number1 number2 &rest numbers)
34 "Return non-nil iff the arguments are coprime, nil otherwise.
35 Numbers are coprime if their gcd is 1."
36 (= 1 (apply #'gcd number1 number2 numbers)))
37 (defalias 'relatively-prime-p #'coprimep)
40 "Return the reciprocal of NUMBER."
43 (defun positivep (number)
44 "Return t if OBJECT is a positive number.
46 We call a number object positive iff it is comparable
47 and it is nonnegative and not a zero."
48 (and (nonnegativep number)
49 (not (zerop number))))
53 (defsubst int (number &optional precision)
54 "Return the ordinary integer numerically equal to NUMBER.
55 The optional argument PRECISION is unused.
57 This is a convenience function analogous to `float'."
58 (coerce-number number 'int precision))
60 (defsubst bigz (number &optional precision)
61 "Return the MPZ number numerically equal to NUMBER.
62 The optional argument PRECISION is unused.
64 This is a convenience function analogous to `float'."
65 (coerce-number number 'bigz precision))
67 (defsubst bigq (number &optional precision)
68 "Return the MPQ number numerically equal to NUMBER.
69 The optional argument PRECISION is unused.
71 This is a convenience function analogous to `float'."
72 (coerce-number number 'bigq precision))
74 (defsubst rational (number &optional precision)
75 "Return a rational most suitable to represent NUMBER.
76 The optional argument PRECISION is unused.
78 This is a convenience function analogous to `float'."
79 (coerce-number number 'rational precision))
83 ;; already implemented
85 (defsubst bigf (number &optional precision)
86 "Return the MPF number numerically equal to NUMBER.
87 If optional argument PRECISION is non-nil, its value
88 \(an integer\) is used as precision.
90 This is a convenience function analogous to `float'."
91 (coerce-number number 'bigf precision))
93 (defsubst bigfr (number &optional precision)
94 "Return the MPFR number numerically equal to NUMBER.
95 If optional argument PRECISION is non-nil, its value
96 \(an integer\) is used as precision.
98 This is a convenience function analogous to `float'."
99 (coerce-number number 'bigfr precision))
101 (defsubst real (number &optional precision)
102 "Return a real with respect to `read-real-as' numerically
104 If optional argument PRECISION is non-nil, its value
105 \(an integer\) is used as precision.
107 This is a convenience function analogous to `float'."
108 (coerce-number number 'real precision))
110 (defsubst bigg (number &optional precision)
111 "Return the Gaussian number numerically equal to NUMBER.
112 The optional argument PRECISION is unused.
114 This is a convenience function analogous to `float'."
115 (coerce-number number 'bigg precision))
117 (defsubst bigc (number &optional precision)
118 "Return the MPC number numerically equal to NUMBER.
119 If optional argument PRECISION is non-nil, its value
120 \(an integer\) is used as precision.
122 This is a convenience function analogous to `float'."
123 (coerce-number number 'bigc precision))
125 (defsubst quatern (number &optional precision)
126 "Return the MPC number numerically equal to NUMBER.
127 If optional argument PRECISION is non-nil, its value
128 \(an integer\) is used as precision.
130 This is a convenience function analogous to `float'."
131 (coerce-number number 'quatern precision))
133 ;;; dealing with norms, valuations and such things
134 (defun canonical-valuation (number)
135 "Return the canonical valuation of NUMBER."
136 (cond ((archimedeanp number)
142 ;;; number.el ends here