You are looking at historical revision 25913 of this page. It may differ significantly from its current revision.
Support for the full numeric tower.
This extension provides support for large exact integers, exact rational and complex numbers.
The following standard procedures are redefined:
+ - * / = > < >= <= abs max min eqv? equal? exp expt log sin cos tan atan asin acos sqrt quotient modulo remainder exact? inexact? exact->inexact inexact->exact positive? negative? even? odd? zero? number? complex? real? rational? integer? gcd lcm truncate ceiling floor round number->string string->number numerator denominator rationalize magnitude angle real-part imag-part
The following standard procedures are provided:
The following non-standard extended procedures are redefined:
add1 sub1 signum bitwise-and bitwise-ior bitwise-xor bitwise-not arithmetic-shift randomize random finite?
Additionally the following procedures are available:[procedure] (infinite? Z)
Is the number Z +inf.0 or -inf.0, or a complex number containing either infinity as its real or imaginary part?
Note: This is not the inverse of finite?, since it produces #f on nan.0 (or complex numbers containing nan.0), while finite? also returns #f in that case.[procedure] (nan? Z)
Is the object Z a real representing nan.0?[procedure] (quotient&remainder A B)
Return the quotient and the remainder of A divided by B.
This is especially useful for bignums, since both numbers are derived simultaneously. This saves performing the division algorithm twice.[procedure] (quotient&modulo A B)
Like quotient&remainder, except return the modulo instead of remainder.[procedure] (conj Z)
Returns the conjugate of the complex number Z.[procedure] (bignum? X)
Is X an extended-precision integer?[procedure] (ratnum? X)
Is X a ratio?[procedure] (cplxnum? X)
Is X a complex?[procedure] (rectnum? X)
Is X an exact-complex? (Treats an integer-floatingpoint as "exact".)[procedure] (compnum? X)
Is X an inexact-complex?[procedure] (cflonum? X)
Is X a floatingpoint-complex or a floatingpoint?[procedure] (cintnum? X)
Is X an integer-complex or an integer?[procedure] (integer-length X)
From SRFI-60; get the number of bits required to represent the integer X in 2s complement notation.
(define (fac n) (if (zero? n) 1 (* n (fac (- n 1))) ) ) ) ) (fac 100) ; => 9332621544394415268169923885626670049071596826438162146859296389 5217599993229915608941463976156518286253697920827223758251185210 916864000000000000000000000000
Bugs and limitations
- Extended number literals can not be used directly in compiled code. Use string->number instead.
About this egg
The code for complex arithmetic was mostly taken from Thomas Chust's complex egg.
The CHICKEN Team
- Correct handling of exactness prefix (requires recent Chicken to work, at least 4.7.4). Division by inexact zero is no longer considered an error, but returns NaN or +Inf/-Inf. inexact->exact raises an error on NaN instead of returning 0 (reported by Felix Winkelmann). Fix log so it doesn't erroneously fail on complex numbers.
- Fix several bugs (expt, integer?, rational?, <=, >=, eqv?, -) found by importing the number tests from Gauche and writing an extensive test for number syntax edge cases. Complete rewrite of number parser (it should fully conform to the R7RS superset of R5RS number syntax now). Dropped dependency on the regex egg. Improved precision of exact->inexact so it can handle more extreme numbers. Provide the nan?, finite? and infinite? predicates and integer-length procedure.
- Fix string->number so it raises an exception instead of crashing when passed a negative, zero or too large base (reported by Peter Hendrickson). Update test scripts so they exit with nonzero status in case of failed tests (reported by Mario Goulart)
- Fix expt and log so they work for numbers which produce complex results.
- Fix expt so it doesn't use flonums and loses precision in case of bignums
- Added regex to dependency list
- Added regex requirement to make it work in Chicken 4.6.2+
- Fixed ratnum normalization in case of negative divisors
- Changed quotient, remainder and quotient&remainder semantics so they accept fractional flonums to match Chicken's implementation of quotient and remainder. This also affects modulo and quotient&modulo.
- Removed dependency on GMP, replacing it by the Scheme48 numbers code. Improved performance by integrating with GC. Added benchmarks and more tests. Converted testsuite to use the test egg instead of testeez. [by Peter Bex]
- removed dependency on easyffi (Thanks to Peter Bex)
- fixed dependencies
- Fix for (expt <number> <ratio>), would fail [Bug noted by John Cowan]
- Fix for 1.0+1i not treated as a rectnum or compnum [Bug noted by John Cowan] Added 'cintnum?' & 'cplxnum?' [kon lovett]
- Fix for equal? when given keywords as args [Bug noted by papasi] [elf]
- Using more accurate exact->inexact conversion for rationals [Alex Shinn]
- fixed bug in fixnum bitwise operations [Thanks to Jeremy Sydik]
- not quite complete support for static linking
- Fixed a bug in angle [zb, mario]
- Single-argument + and * didn't check argument type [Thanks to Stephen Gilardi]
- Bugfix for compiler macros, undefined symbol [Kon Lovett]
- Added compiler macros for bitwise-... operations
- Compiler macros now work without -X numbers
- Added support for speculative inlining of fixnum ops
- Fixed bug in ratnum/bignum division [Thanks to Ivan Shmakov]
- Fixing round for rational numbers [Alex Shinn]
- Added bignum? ratnum? cflonum? rectnum? compnum? [Kon Lovett]
- Uses easyffi properly [reported by John Cowan]
- Fix for fixnum/rational comparison [by Zbigniew]
- rational? always returned false for flonums
- Added some missing definitions to numbers.scm [found by Kon Lovett]
- Fixed memory leak in some bitwise operations [found by Dan Muresan]
- Fixed a bug in expt [Daishi Kato]
- round rounds to even (as specified by R5RS) [Thanks to Benedikt Rosenau]
- Reimplemented = in C
- Fixed equal? which didn't handle extended numbers nested in other data
- Slight performance tuning for expt [Again by Daishi]
- Fixed bug in fixnum/bignum subtraction [Thanks to Daishi Kato and Alex Shinn]
- Speed improvements for expt by Daishi Kato
- Added random and randomize [Suggested by Daishi Kato]
- bignum/fixnum subtraction used wrong argument order [Thanks to Kon Lovett]
- Several bug fixes by Alex Shinn; signum is exactness preserving
- Alex Shinn contributed a working version of expt
- Yet another bug-fix by Michal
- Several bug-fixes by Michal Janeczek
- exactness handling of expt is slightly better but still not perfect.
- Fixed bug in integer?
Copyright (c) 2008-2012 The CHICKEN Team Copyright (c) 2000-2007, Felix L. Winkelmann Copyright (c) 1993-2008 Richard Kelsey and Jonathan Rees Copyright 1986,1987,1988,1989,1990,1991 Massachusetts Institute of Technology Copyright 1992,1993,1994,2004 Massachusetts Institute of Technology All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.