[clean-list] Handling of reals & boolean expressions?

Richard A. O'Keefe ok@cs.otago.ac.nz
Fri, 20 Dec 2002 11:54:41 +1300 (NZDT)


John van Groningen excuses the strange results of floating point
comparison by saying that other languages do it.

But this has been recognised as a bug by many compiler writers.
The C compiler I use has the command line switch '-fstore'
precisely to ensure that expressions like x+y == x get a reasonable
semantics.

GCC has the command line flag -ffloat-store for the same reason.
Unfortunately, it doesn't _quite_ do the right thing.  The problem
is not storing FP values in registers, it is failing to round
results back to the correct language-defined precision before
comparison.

The Pentium's floating point unit has a control word.
In that control word, there is a precision field.
The precision field can be set so that all calculations
yield a result with 53 bits of significance.
(Pentium-Pro reference manual, volume 2, section 7.3.4.)
If the "PC" field of the FPU control word is set to 53-bit mode,
then the computed results should be the same AS IF they were
converted to IEEE double, stored, and then loaded again.

It might be worth offering a compiler option to set this mode.