DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(r5rs.info.gz) Numerical input and output

Info Catalog (r5rs.info.gz) Numerical operations (r5rs.info.gz) Numbers
 
 6.2.6 Numerical input and output
 --------------------------------
 
  -- procedure: number->string z
  -- procedure: number->string z radix
      RADIX must be an exact integer, either 2, 8, 10, or 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
                                              radix)
                              radix)))
 
      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 [howtoprint], [howtoread];
      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.
 
 
  -- procedure: string->number string
  -- procedure: string->number string radix
      Returns a number of the maximally precise representation expressed
      by the given STRING.  RADIX must be an exact integer, either 2, 8,
      10, or 16.  If supplied, RADIX is a default radix that may be
      overridden by an explicit radix prefix in STRING (e.g. "#o177").
      If RADIX is not supplied, then the default radix is 10.  If STRING
      is not a syntactically valid notation for a number, then
      `string->number' returns #f.
 
      (string->number "100")                 ==>  100
      (string->number "100" 16)              ==>  256
      (string->number "1e2")                 ==>  100.0
      (string->number "15##")                ==>  1500.0
 
           _Note:_ The domain of `string->number' may be restricted by
           implementations in the following ways.  `String->number' is
           permitted to return #f whenever STRING contains an explicit
           radix prefix.  If all numbers supported by an implementation
           are real, then `string->number' is permitted to return #f
           whenever STRING uses the polar or rectangular notations for
           complex numbers.  If all numbers are integers, then
           `string->number' may return #f whenever the fractional
           notation is used.  If all numbers are exact, then
           `string->number' may return #f whenever an exponent marker or
           explicit exactness prefix is used, or if a # appears in place
           of a digit.  If all inexact numbers are integers, then
           `string->number' may return #f whenever a decimal point is
           used.
 
 
Info Catalog (r5rs.info.gz) Numerical operations (r5rs.info.gz) Numbers
automatically generated byinfo2html