Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
Comparison succeeds

Wiki Markup
The reason for this behavior is that Linux utilizes the internal extended precision mode of the x87 FPU on IA-32 machines for increased accuracy during computation.  When the result is stored into memory by the assignment to {{c}}, the FPU automatically rounds the result to fit into a {{double}}.  Later, when the value is read back from memory and compared to the internal representation (which has extended precision), the comparison fails, producing an unexpected result.  Windows does not use the extended precision mode, so all computation is done with double precision and there are no differences in precision between values stored in memory and those internal to the FPU.  On Linux, compiling with the {{-O}} optimization flag eliminates the unnecessary store into memory, so all computation happens within the FPU with extended precision \[[Gough 2005|AA. C References#Gough 2005]\].

Risk Analysis

Failing to understand the limitations of floating point numbers can result in unexpected mathematical results and exceptional conditions, possibly resulting in a violation of data integrity.

...