chickadee » scheme » number->string

number->string z #!optional radixprocedure

Radix must be an exact integer. The R5RS standard only requires implementations to support 2, 8, 10, or 16, but CHICKEN allows any radix between 2 and 36, inclusive (note: a bug in CHICKEN 5 currently limits the upper bound to 16). If omitted, radix defaults to 10. The procedure number->string takes a number and a radix and returns as a string an external representation of the given number in the given radix such that

(let ((number number)
      (radix radix))
  (eqv? number
        (string->number (number->string number

is true. It is an error if no possible result makes this expression true.

If z is inexact, the radix is 10, and the above expression can be satisfied by a result that contains a decimal point, then the result contains a decimal point and is expressed using the minimum number of digits (exclusive of exponent and trailing zeroes) needed to make the above expression true [3, 5]; otherwise the format of the result is unspecified.

The result returned by number->string never contains an explicit radix prefix.

Note: The error case can occur only when z is not a complex number or is a complex number with a non-rational real or imaginary part.

Rationale: If z is an inexact number represented using flonums, and the radix is 10, then the above expression is normally satisfied by a result containing a decimal point. The unspecified case allows for infinities, NaNs, and non-flonum representations.

As an extension to R5RS, CHICKEN supports reading and writing the special IEEE floating-point numbers +nan, +inf and -inf, as well as negative zero.