Versions Compared

Key

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

Floating-point variables must not be used as loop counters. Limited-precision binary IEEE 754 floating-point numbers types cannot represent

...

  • all simple

...

  • fractions exactly
  • all decimals precisely, even when the decimals can be represented in a small number of digits.
  • all digits of large values, meaning that incrementing a large floating-point value might not change that value within the available precision.

Noncompliant Code Example

...

The CERT C Secure Coding Standard

FLP30-C. Do not use floating point variables as loop counters

The CERT C++ Secure Coding Standard

FLP30-CPP. Do not use floating point variables as loop counters

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="15e6c0ebaee6c590-24e0a398-453b469a-89218445-1976e93e16923ce864092c7d"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

"Floating?point Arithmetic [PLF]"

]]></ac:plain-text-body></ac:structured-macro>

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ad057ba8ce976573-ee516d86-4d4d498a-8dd1bd46-8b1fbb3f28712f135806dbcc"><ac:plain-text-body><![CDATA[

[[Bloch 2005

AA. Bibliography#Bloch 05]]

Puzzle 34: Down for the Count

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c672df5084043830-c19ecad8-4fa94156-a8a5af50-d0bcda309ee6c48017674f1f"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

[§4.2.3, "Floating-Point Types, Formats, and Values"

http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3]

]]></ac:plain-text-body></ac:structured-macro>

...