wiki:NumericTower

Version 29 (modified by cowan, 4 years ago) (diff)

--

The numeric tower

This is an analysis of the R5RS provision that the full numeric tower may be subsetted. In this analysis, four boolean feature settings characterize different kinds of numeric towers: exactness-preserving, ratios, inexact, and complex. These refer respectively to the closure of exact numbers under rational operations (except /), exact non-integer values, inexact rationals, and non-real numbers.

There are therefore 16 possible numeric towers. 9 of them are known to have implementations, as shown below. I write + if a feature is present and - if it is absent, and give a general description of the resulting tower and some Scheme implementations that provide it.

exactness-preservingratiosinexactcomplexDescriptionImplementations
----Bounded exact integers onlySigScheme*
--+-Fixnums and flonumsPlain Chicken, Shoe*, TinyScheme*, RScheme, JScheme*, BDC*, XLisp*, Schemik*, VX, SXM*, Inlab, Llava, Sixx, Sizzle, Dfsch*, Stalin (also Elisp*, C*)
-++-Limited-range exact and inexact real numbersNexJ (also Java)
-+++Limited-range exact and inexact numbersS7, Wraith
+-+-Exact integers and inexact real numbersBigloo, Scheme 9, Elk (also ISLisp)
+-++Exact integers, inexact real numbers, and complex numbersSCM
++--Exact rational numbers onlyDream, Oaklisp, Owl Lisp
+++-Real numbers onlyPsyche, Ikarus, Rep, Dfsch (also Clojure)
++++Full numeric towerRacket, Gauche, MIT, Gambit, Chicken with the numbers egg, Scheme48/scsh, Kawa, SISC, Chibi, Guile, Chez, Vicare, Larceny, Ypsilon, Mosh, IronScheme, STklos, KSi, UMB, Spark (also R6RS, Common Lisp, Pure)

*These systems are technically exactness-preserving, but silently return the wrong answers when their arithmetic operations overflow. This makes them non-conformant.

Opinions

In my opinion, the reasonable general-purpose towers are --+- (fixnums and flonums), +-+- (fixnums, bignums, and flonums), +++- (fixnums, bignums, ratnums, and flonums) and ++++ (full). The --+- tower's operations have the advantage of running in constant time on modern hardware. The ++-- tower (ratnums but not flonums) may be reasonable for some purposes, but numerical code will often run very slowly without inexact support due to fractions which grow larger and larger. The ---- (fixnum-only) tower might possibly be appropriate where only a tiny amount of space is available and essentially no numerical work will be done.

See NumericTowerManisComments for Vincent Manis's comments on an earlier version of this page.

See also

See also ComplexRepresentations for information on which Schemes support exact, inexact, and mixed-exactness complex numbers.

See also FloatPrecision for information on the different precisions of inexact numbers that some Schemes support.