[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Scheme-reports] Padding/placeholders (hashes) in numerical syntax
Vincent St-Amour scripsit:
> In Racket, `e' is used for double-precision floats, and `f' for
> single-precision. In the absence of either, double-precision is the
> default (but this can be configured when building Racket).
According to a survey I did back in 2009, Kawa and SCM also provide
single and double floats, but there is no way within R5RS to distinguish
them: eqv? defers to = for all numbers. At that time, neither did
anything useful with the exponent markers.
R6RS seems to require that in Racket (eqv? 1.0f0 1.0e0) returns #f,
because R6RS section 11.5 says:
The eqv? procedure returns #f [...] Obj1 and obj2 yield different
results (in the sense of eqv?) when passed as arguments to any other
procedure that can be defined as a finite composition of Scheme's
standard arithmetic procedures.
In particular, because 1/3 is not representable as a binary IEEE value,
(/ 1.0f0 3.0f0) should return a different value from (/ 1.0e0 1.0e0).
There are an even number of bits in a single-float mantissa and an odd
number of bits in a double-float mantissa. Consequently, the bits
beyond the rounding point are 1010... in single float, 0101... in double
float. 1010... is more than half an ulp and must round up, whereas
0101... is less than half an ulp and must round down.
This is why ISO changed C to do single-float expressions in single-float
arithmetic; the pre-ANSI practice was that all float operations were
done in double float. But in Racket (eqv? 1.0f0 1.0e0) returns #t and
so does (= (/ 1.0f0 3.0f0) (/ 1.0e0 3.0e0)).
Here lies the Christian, John Cowan
judge, and poet Peter, http://www.ccil.org/~cowan
Who broke the laws of God cowan@x
and man and metre.
Scheme-reports mailing list