1. Synopsis
  2. Interface
  3. Example
  4. Bugs and limitations
  5. About this egg
    1. Author
    2. Requirements
    3. Version history
    4. License

Synopsis

Support for the full numeric tower.

Interface

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:

make-rectangular  make-polar

The following non-standard extended procedures are redefined:

add1         sub1
signum
bitwise-and  bitwise-ior  bitwise-xor  bitwise-not  arithmetic-shift
randomize    random

Additionally the following procedures are available:

[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] (cflonum? X)

Is X an inexact-complex or a floatingpoint?

[procedure] (rectnum? X)

Is X an exact-complex?

[procedure] (compnum? X)

Is X an inexact-complex?

Example

(define (fac n)
  (if (zero? n)
      1
      (* n (fac (- n 1))) ) ) ) )
(fac 100)   
; => 9332621544394415268169923885626670049071596826438162146859296389
     5217599993229915608941463976156518286253697920827223758251185210
     916864000000000000000000000000

Bugs and limitations

About this egg

Author

felix

The code for complex arithmetic was mostly taken from Thomas Chust's complex egg.

Requirements

The GNU Multiple Precision Arithmetic Library must be installed.

Version history

1.806
Fix for equal? when given keywords as args [Bug noted by papasi] [elf]
1.804
Using more accurate exact->inexact conversion for rationals [Alex Shinn]
1.803
fixed bug in fixnum bitwise operations [Thanks to Jeremy Sydik]
1.802
not quite complete support for static linking
1.801
Fixed a bug in angle [zb, mario]
1.8
Single-argument + and * didn't check argument type [Thanks to Stephen Gilardi]
1.701
Bugfix for compiler macros, undefined symbol [Kon Lovett]
1.7
Added compiler macros for bitwise-... operations
1.6
Compiler macros now work without -X numbers
1.5
Added support for speculative inlining of fixnum ops
1.4
Fixed bug in ratnum/bignum division [Thanks to Ivan Shmakov]
1.3
Fixing round for rational numbers [Alex Shinn]
1.2
Added bignum? ratnum? cflonum? rectnum? compnum? [Kon Lovett]
1.1
Uses easyffi properly [reported by John Cowan]
1.0
Fix for fixnum/rational comparison [by Zbigniew]
0.999
rational? always returned false for flonums
0.998
Added some missing definitions to numbers.scm [found by Kon Lovett]
0.997
Fixed memory leak in some bitwise operations [found by Dan Muresan]
0.996
Fixed a bug in expt [Daishi Kato]
0.995
round rounds to even (as specified by R5RS) [Thanks to Benedikt Rosenau]
0.994
Reimplemented = in C
0.993
Fixed equal? which didn't handle extended numbers nested in other data
0.992
Slight performance tuning for expt [Again by Daishi]
0.991
Fixed bug in fixnum/bignum subtraction [Thanks to Daishi Kato and Alex Shinn]
0.99
Speed improvements for expt by Daishi Kato
0.98
Added random and randomize [Suggested by Daishi Kato]
0.97
bignum/fixnum subtraction used wrong argument order [Thanks to Kon Lovett]
0.96
Several bug fixes by Alex Shinn; signum is exactness preserving
0.95
Alex Shinn contributed a working version of expt
0.94
Yet another bug-fix by Michal
0.93
Several bug-fixes by Michal Janeczek
0.92
exactness handling of expt is slightly better but still not perfect.
0.91
Fixed bug in integer?
0.9
(beta)

License

Copyright (c) 2005-2007, Felix L. Winkelmann
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

 Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer. 
 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. 
 Neither the name of the author nor the names of its contributors
   may be used to endorse or promote products derived from this
   software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"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 COPYRIGHT
HOLDERS OR CONTRIBUTORS 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.