For Development HEAD DRAFTSearch (procedure/syntax/module):

11.75 srfi.270 - Hexadecimal floating-point constants

Module: srfi.270

Gauche’s built-in procedures understand hexadecimal floating-point consntants:

(string->number "#x1.fp-1")  ⇒ 0.96875
(string->number "1.fp-1" 16) ⇒ 0.96875

(number->string 3.14 16) ⇒ "1.91eb851eb851fp1"

See Numeric literal syntax, for the details.

This module exports one auxiliary procedure defined in srfi-270.

Function: write-hexadecimal-float z :optional port

[SRFI-270]{srfi.270} First, z is converted to an inexact number, then it is written out using hexadecimal floating-poit number notation to the given port, or the current output port is port is omitted.

  • No prefix (#x or #e) is written
  • If the number is 0.0 or -0.0, it is printed with a zero exponent, e.g. 0.0p0 or -0.0p0.
  • If the floating-point number is in normalized range, the mantissa part begins with “1.”.
  • If the floating-point number is in denormalized range, the mantissa part begins with “0.”.
  • NaN and infinities are written normally, i.e. +nan.0 etc.
  • If z is a complex number with an imaginary part, both real part and imaginary part are written in hexadecimal floating-point format.
(write-hexadecimal-float 6.02e23) ⇒ 1.fde9f10a8d361p78
(write-hexadecimal-float 1e-310)  ⇒ 0.93445b873158p-1029


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT