Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: made this guideline consistent with NUM00 and JLS 4.2.3

...

On platforms whose native floating point hardware provides greater precision than double, the JIT is permitted to use floating point registers to hold values of type float or type double (in the absence of the strictfp modifier), even though the registers support values with greater mantissa and/or exponent range than that of the primitive types. Consequently, conversion from float to double can cause an effective loss of precision, magnitude, or both.

Code Block
bgColor#FFcccc
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();
  }
}

The lost precision or magnitude would also have been lost if the value were stored to memory, for example to a field of type float.

...

Failure to use the strictfp modifier can result in implementation-defined behavior , with respect to the accuracy behavior of floating point operations.

...