Mail Archives: djgpp/2000/06/27/15:37:18
Erik Berglund <erik2 DOT berglund AT telia DOT com> wrote:
> Hi, I tried the following program, which gives
> j=9999. I think the right result should be 10000,
> because a=0x40c3880000000000, which is exactly 10000.
In a nutshell: hidden extra precision. The FPU registers keep
temporary results in 'long double' precision. Only if you force the
values back into memory (like your access to it via pointers to
integer does it), they'll become proper double's again. Microscopic
differences in results may be generated by the optimizer moving around
code, in this situation.
Morale: don't *ever* rely on the contents of the last (few) binary
digits of floating point numbers. They're allowed to behave totally
unpredictably. Don't try to understand the logic behind their
behaviour --- there is none.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -