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

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

...

Bibliography

[Darwin 2004]

Ensuring the Accuracy of Floating-Point Numbers

[JLS 2005]

§15.4, FP-strict Expressions

[JPL 2006]

9.1.3, Strict and Non-Strict Floating-Point Arithmetic

[McCluskey 2001]

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

 

...

Image Modified      Image Modified      Image Modified