[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scheme flonum literals

This page is part of the web mail archives of SRFI 58 from before July 7th, 2015. The new archives for SRFI 58 contain all messages, not just those from before July 7th, 2015.

Just FYI, a little more background on Scheme's exponent markers:

A couple days ago, I wrote up this table with my best guess at how the
Scheme flonum precisions correspond to IEEE 754 and C floating-point

>     IEEE 754 format     C type          Scheme precision
>     ----------------------------------------------------
>     single              float           f/single
>     single extended     N/A             s/short (?)
>     double              double          d/double
>     double extended     long double     l/long

I was correct to put a (?) after the s/short entry -- it doesn't belong
there. For one thing, an IEEE 754 system wouldn't normally have both
extended formats. More importantly, s/short should not be more precise
than f/single.

Today, I was browsing CLTL2, and I stumbled across the Common Lisp rules
for flonum literals. CL uses exactly the same set of flonum types, but
unlike R5RS it actually explains their rationale and meaning. It's good
stuff, and Scheme systems should follow it even though it isn't
documented in R5RS.

S/short is for the system's smallest flonum type. Ideally, a short
flonum should be small enough to fit (unboxed) in a cell. On a 32-bit
system, I think you could do that by reserving the least significant
bits of an IEEE 754 "single" for type tags, just like most systems do
with fixnums.

L/long is for the system's largest flonum type.

F/single and D/double allude to the IEEE 754 basic formats and should
use those formats if they're available. Why "F"? Probably because
"short" and "single" both start with S, and only one of them had an
obvious alternate abbreviation (I don't think it's any coincidence that
F, D, L also stand for float, double, long double).

An x86 Lisp/Scheme system could implement the four flonum formats thus:

S/short  = IEEE 754 single with type tags stuffed in the significand
F/single = IEEE 754 single (binary32)
D/double = IEEE 754 double (binary64)
L/long   = x86 extended precision (binaryx)
Bradd W. Szonye