[r6rs-discuss] Confusion over |p

From: Alan Watson <alan>
Date: Fri, 29 Jun 2007 18:57:26 -0500

William D Clinger wrote:
> How much?

All of this week's pocket money!

>> Here is the problem I want to solve. I want to be able to read IEEE
>> singles and doubles and have them represented by the nearest inexact
>> real. I want to be able to write the IEEE single and double that is
>> nearest to a given inexact real. I am prepared to accept a solution that
>> works on many but not all implementations and I am prepared to do some
>> of the work myself.
>
> If the R6RS were to require implementations to read x|p
> as the best p-bit binary floating point approximation to
> x, then the R6RS would solve your problem.

I said I am prepared to do *some* of the work. Only normalized numbers
have 24 bits or 53 bits of precision. I would have to calculate p for
each denormalized x; that's too much work.

> The current draft R6RS does not require that, and I don't
> see how it could be revised to require that without also
> requiring implementations to represent inexact numbers in
> binary floating point.

I don't see what this has got to do with the internal representation of
inexact numbers.

The notation x|p denotes a unique mathematical binary floating point
number, at least under Mike Sperber's interpretation and under the one
you mention above (provided "best" is expanded to specify rounding).

Of course, the mapping from that mathematical number to an internal
inexact number does not have to preserve this value, but that has
nothing to do with x|p per se.

> In practice, however, I think the
> current draft R6RS would accomplish exactly what you want,
> assuming implementors of the R6RS pay attention to this.
>
>> (a) We keep |p but give is some kind of sane semantics.
>
> The meaning of x|p is mathematically well-defined, and is
> pretty clear from the current draft: x|p "represents the
> best binary floating-point approximation of x using a
> p-bit significand."

The problem is not so much with x|p as with the rules for adding an
implicit |p when none is given. They are currently insane. It might be
possible to fix them, though.

> In my opinion, standard practice should be to read x|p
> with no loss of precision or accuracy when p <= 53, and
> to represent x|p as accurately as possible if p exceeds
> the highest precision provided by a implementation.

If I understand correctly, that would make it a NOP on implementations
that use IEEE doubles for all inexact reals.

How then do I write a number that ends up being interpreted as the value
of 1.1 truncated to 24 bits? If I know that inexacts are IEEE doubles, I
can simply write the decimal approximation that rounds to the correct
value. However, this decimal approximation might not work for other
formats, like IEEE double extended. It also does very little to convey
my intent.

Regards,

Alan
Received on Fri Jun 29 2007 - 19:57:26 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC