Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider v2.4 (sch jbop) (X_X)@==(Q_Q)@

...

By definition, a floating point number is of finite precision, and regardless of the underlying implementation, is prone to errors associated with rounding (see FLP01-AC. Take care in rearranging floating point expressions and FLP02-AC. Consider avoiding floating point numbers when precise computation is needed).

...

Wiki Markup
The reason for this behavior is that Linux uses the internal extended precision mode of the x87 floating point unit (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}}. The value read back from memory now compares unequal to the internal representation (which has extended precision), which is typically 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.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

FLP00-A C

medium

probable

high

P4

L3

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[Gough 2005|AA. C References#Gough 2005]\] [Section 8.6, "Floating-point issues"|http://www.network-theory.co.uk/docs/gccintro/gccintro_70.html]
\[[IEEE 754 2006|AA. C References#IEEE 754 2006]\]
\[[ISO/IEC 9899-:1999|AA. C References#ISO/IEC 9899-1999]\] Section 5.2.4.2.2, "Characteristics of floating types {{<float.h>}}"
\[[ISO/IEC PDTR 24772|AA. C References#ISO/IEC PDTR 24772]\] "PLF Floating Point Arithmetic"

...

05. Floating Point (FLP)      05. Floating Point (FLP)       FLP01-AC. Take care in rearranging floating point expressions