Versions Compared

Key

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

...

Code Block
bgColor#ccccff
strictfp class Example {
  double d = 0.0;

  public void example() {
    float f = Float.MAX_VALUE;
    float g = Float.MAX_VALUE;
    this.d = f * g;
    System.out.println("d (" + this.d + ") might not be equal to " + (f * g));
  }

  public static void main(String[] args) {
    Example ex = new Example();
    ex.example();
  }
}

Exceptions

NUM09NUM06-EX1: This rule applies only to calculations that require consistent floating-point results on all platforms. Applications that lack this requirement need not comply.

NUM09NUM06-EX2: The strictfp modifier may be omitted when competent numerical analysis demonstrates that the computed values will meet all accuracy and behavioral requirements that are appropriate to the application. Note that "competent numerical analysis" generally requires a specialized professional numerical analyst; lesser levels of rigor fail to qualify for this exception.

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

NUM09 NUM06-J

low

unlikely

high

P1

L3

Automated Detection

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c9b3da475f29f28a-916f2e8f-4d7b40e2-9090a712-fa04b2664d6489a6a2e95d1e"><ac:plain-text-body><![CDATA[

[[Darwin 2004

AA. Bibliography#Darwin 04]]

Ensuring the Accuracy of Floating-Point Numbers

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="28d66012e38c264b-69fbebbc-4d8f4aec-b08eb16a-5b02ef9779b4911bd75d2d6b"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

[§15.4, "FP-strict Expressions"

http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.4]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f434a36a5ff06d8f-1e6ee668-47294d4b-8872b0da-0992e2ceb4cfb95e01b79116"><ac:plain-text-body><![CDATA[

[[JPL 2006

AA. Bibliography#JPL 06]]

9.1.3. Strict and Non-Strict Floating-Point Arithmetic

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bbfc0b9e060178ab-adf36e1a-4b524af2-8fcc9177-044a4af4d2fc959e2ce70cd6"><ac:plain-text-body><![CDATA[

[[McCluskey 2001

AA. Bibliography#McCluskey 01]]

Making Deep Copies of Objects, Using strictfp, and Optimizing String Performance

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

...