Versions Compared

Key

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

Wiki Markup
The Java language provides two primitive floating-point types, {{float}} and {{double}}, which are associated with the single-precision 32-bit and double-precision 64-bit format values and operations specified by IEEE 754 \[[IEEE 754|AA. Bibliography#IEEEReferences#IEEE 754 2006]\]. Each of the floating-point types has a fixed, limited number of mantissa bits. Consequently, it is impossible to precisely represent any irrational number (for example, pi). Further, because these types use a binary mantissa, they cannot precisely represent many finite decimal numbers, such as 0.1, because these numbers have repeating binary representations.

...

Wiki Markup
When precise computation is unnecessary, floating-point representations may be used. In these cases, you must carefully and methodically estimate the maximum cumulative error of the computations to ensure that the resulting error is within acceptable tolerances. Consider using numerical analysis to properly understand the problem. See Goldberg's work for an introduction to this topic \[[Goldberg 1991|AA. Bibliography#GoldbergReferences#Goldberg 91]\].

Noncompliant Code Example

...

The CERT C Secure Coding Standard

FLP02-C. Avoid using floating point numbers when precise computation is needed

The CERT C++ Secure Coding Standard

FLP02-CPP. Avoid using floating point numbers when precise computation is needed

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="517a7d888d7bff1b-d5be2b4a-483d489e-96af8695-8a7fdaaffdc97e8f7efdc182"><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="546248d45f0aa357-54db5a05-4bbb4539-a553b6bd-4bba9a46ed62c66f4eca8d9d"><ac:plain-text-body><![CDATA[

[[Bloch 2008

AA. Bibliography#Bloch References#Bloch 08]]

Item 48. Avoid float and double if exact answers are required

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b9dc55aa7c3bdc4d-b2ef3138-4506498c-b3eb9753-70da24c343adf14bf916561c"><ac:plain-text-body><![CDATA[

[[Bloch 2005

AA. Bibliography#Bloch References#Bloch 05]]

Puzzle 2. Time for a change

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d4d2ea3a34725295-2e12e3cf-46f246d6-b673a571-de030733cf7fb4a999cf6289"><ac:plain-text-body><![CDATA[

[[Goldberg 1991

AA. Bibliography#Goldberg References#Goldberg 91]]

 

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ade666ffecb64cff-d3320225-433d4130-ad13a2fe-619667f3e387458efe32a08f"><ac:plain-text-body><![CDATA[

[[IEEE 754

AA. Bibliography#IEEE References#IEEE 754 2006]]

 

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b4795d35d2eafd26-ffc87cc8-443b4d0b-b9a4a0ef-a1dc67a08a1e3f9b49762b20"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS References#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>

...