This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see FloatPrecision in WG2's repo for R7RS-large.

# Float­Precision

2012-12-16 04:28:30
source

Scheme (before R7RS) and Common Lisp require that implementations understand short-float, single-float, double-float and long-float syntax. These are written by replacing the e of exponential notation with an s, f, d, or l respectively. However, there is no requirement that any of these be distinct, only that they be consistent: short-floats cannot have more precision than long-floats, for example. Common Lisp requires that e notation be equivalent to f notation by default; Scheme has no such requirement.

I asked the usual Schemes and some Common Lisps to evaluate 3.1415926535897932385s0, 3.1415926535897932385f0, 3.1415926535897932385d0, and 3.1415926535897932385l0, where the numeric value is a 64-bit version of π. Common Lisps were asked about precision directly using the standard float-bits procedure. For Scheme, I inferred how many bits of precision were provided by the answers. Here are the results:

All four numbers are the same and have 53-bit precision (IEEE double): Gauche, Gambit, Chicken (with or without the numbers egg)*, Guile*, Kawa, SISC, Chibi, SCM, Chez, Vicare, Larceny, Ypsilon, Mosh, IronScheme, STklos*, KSI†, Scheme 7†, UMB, VX*, SXM*, Spark, Dfsch†, Inlab*

All four numbers are the same and have 64-bit precision: Scheme 9*

All four numbers are the same and have 20-bit precision: Shoe

The first two numbers have 24-bit precision (IEEE single), the last two have 53-bit precision (IEEE double): Racket, NexJ, Armed Bear CL, Allegro CL, Clozure CL, CMU CL, Embeddable CL, GNU CL, Steel Bank CL, Scieneer CL

The numbers have 19-bit, 24-bit, 53-bit, and 53-bit precision respectively: LispWorks

The numbers have 17-bit, 24-bit, 53-bit, and 64-bit precision respectively: CLISP

No inexact numbers: SigScheme, Dream, Oaklisp, Owl Lisp

Report syntax errors or treat input as identifiers: Bigloo, Scheme48/scsh, TinyScheme, Dream, RScheme, BDC, XLisp, Rep, Schemik, Elk, Sizzle, FemtoLisp

Inputs are treated as as special lexical syntax, not as numbers: Llava

*Output is truncated

†Output is printed incorrectly