Bernd Paysan wrote:
On Saturday 25 January 2003 14:54, Anton Ertl wrote:

There's a reason to prefer the first version.  Sometimes you
want an accurate decimal representation of a radix 2, 64-bit
floating point number considered as exact.

>> [...]

Generally, you should not considder FP numbers as exact representation, but as interval of value+-eps/2. Therefore I think it's ok for ecvt() to stop when there's only one FP representation for this number, i.e. conversion is clear in both ways.
That's certainly a generally good way to consider FP numbers, but there are cases where you want to treat the internal representation as exact, when the decimal representation cannot be. Then I think it's a graceful default for the display of decimal digits beyond the machine precision to mean something.

I don't intend to pose as an FP expert, having just been learning some of this stuff. But here's an example. The Kahan algorithm for computing CABS at one point splits 1+sqrt(2) into 2 parts,


r2p1 = 1 + sqrt(2)

and

t2p1 = [1 + sqrt(2)] - r2p1 .

If I understand correctly, r2p1 is supposed to be exact to machine precision, i.e., the truncation of the double (or quad) precision representation. The algorithm is then careful about the order of adding pieces, so it gets better accuracy.

Then you have the problem, how to get r2p1 and t2p1 into the machine in Forth.

I've done this two ways. The first was to compute in hex with Mathematica, and construct the raw representations by hand. It was then very comforting to be able to print out the decimal representations to around 40 digits with F., add them up, and see that I got 1+sqrt(2) to nearly 34 significant digits, twice the machine precision.

(I wrote an ANS Forth program to insert raw FP strings into the machine. Petrus has a word like that in his Forth lexicon.)

I believe a better way to do the insertion is with a variant of >FLOAT that reads C99 mixed hex/radix 2 FP strings. I've written most of one of those, too, for IEEE 32-bit and 64-bit numbers.

-- David




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to