david at cantrell.org.uk
Mon Jan 15 16:37:25 GMT 2007
On Mon, Jan 15, 2007 at 10:55:31AM +0000, Nicholas Clark wrote:
> The only way I can think of doing it is to forgo floating point hardware
> completely and code all operations longhand in integer operations. There
> may be better ways, but I'd be surprised if they were fast.
My understanding is that if all operands can be precisely represented in
floating point, and if the result is in range, then there is no loss of
precision. Out-of-range errors *can* be detected, of course. I'd be
surprised if modern hardware couldn't also raise a flag indicating that
there had been a rounding error, although back-tracking through the
entire program to re-do all the calculations in the int world would be
Determining whether a value can be precisely represented is left as an
exercise for the reader, but to start with, any number constructed from
1/(2^n) is (again, provided it's in range, and for integer n (and I
think for any n that is precisely represented in floating point ...)).
You (for p5p values of you) could hypothetically add a flag to the
gigantic structure that represents numbers in perl to note if a number
is precise and propagate it to numbers calculated from those numbers.
Of course, as soon as a calculation involves an imprecise number, the
result is imprecise.
David Cantrell | Hero of the Information Age
I remember when computers were frustrating because they did
exactly what you told them to. That seems kinda quaint now.
-- JD Baldwin, in the Monastery
More information about the london.pm