Previous: , Up: scheme lex syntax   [Index]


3.4.3.8 Numbers

The syntax of external representations for number objects is described formally by the ?number rule in the formal grammar. Case is not significant in external representations of number objects.

A representation of a number object may be written in binary, octal, decimal, or hexadecimal by the use of a radix prefix. The radix prefixes are #b (binary), #o (octal), #d (decimal), and #x (hexadecimal). With no radix prefix, a representation of a number object is assumed to be expressed in decimal.

A representation of a number object may be specified to be either exact or inexact by a prefix. The prefixes are #e for exact, and #i for inexact. An exactness prefix may appear before or after any radix prefix that is used. If the representation of a number object has no exactness prefix, the constant is inexact if it contains a decimal point, an exponent, or a nonempty mantissa width; otherwise it is exact.

In systems with inexact number objects of varying precisions, it may be useful to specify the precision of a constant. For this purpose, representations of number objects may be written with an exponent marker that indicates the desired precision of the inexact representation. The letters s, f, d, and l specify the use of short, single, double, and long precision, respectively. (When fewer than four internal inexact representations exist, the four size specifications are mapped onto those available. For example, an implementation with two internal representations may map short and single together and long and double together.) In addition, the exponent marker e specifies the default precision for the implementation. The default precision has at least as much precision as double, but implementations may wish to allow this default to be set by the user.

3.1415926535898F0
       Round to single, perhaps 3.141593
0.6L0
       Extend to long, perhaps .600000000000000

A representation of a number object with nonempty mantissa width, x|p, represents the best binary floating–point approximation of x using a p–bit significand. For example, 1.1|53 is a representation of the best approximation of 1.1 in IEEE double precision. If x is an external representation of an inexact real number object that contains no vertical bar, then its numerical value should be computed as though it had a mantissa width of 53 or more.

Implementations that use binary floating–point representations of real number objects should represent x|p using a p–bit significand if practical, or by a greater precision if a p–bit significand is not practical, or by the largest available precision if p or more bits of significand are not practical within the implementation.

Note The precision of a significand should not be confused with the number of bits used to represent the significand. In the IEEE floating–point standards, for example, the significand’s most significant bit is implicit in single and double precision but is explicit in extended precision. Whether that bit is implicit or explicit does not affect the mathematical precision. In implementations that use binary floating point, the default precision can be calculated by calling the following procedure:

(define (precision)
  (do ([n 0 (+ n 1)]
       [x 1.0 (/ x 2.0)])
    ((= 1.0 (+ 1.0 x)) n)))

Note When the underlying floating–point representation is IEEE double precision, the |p suffix should not always be omitted: Denormalized floating–point numbers have diminished precision, and therefore their external representations should carry a |p suffix with the actual width of the significand.

The literals +inf.0 and -inf.0 represent positive and negative infinity, respectively. The +nan.0 literal represents the NaN that is the result of (/ 0.0 0.0), and may represent other NaNs as well. The -nan.0 literal also represents a NaN.

If x is an external representation of an inexact real number object and contains no vertical bar and no exponent marker other than e, the inexact real number object it represents is a flonum (see library section “Flonums”). Some or all of the other external representations of inexact real number objects may also represent flonums, but that is not required by this report.


Previous: , Up: scheme lex syntax   [Index]