Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
bgColor#FFcccc
class Strictfp {
  public static void main(String[] args) {
    double d = Double.MAX_VALUE;
    System.out.println(""This value \"""" + ((d * 1.1) / 1.1) + "\""\" cannot be represented as double."");
  }
}

Compliant Solution

To be compliant, use the strictfp modifier within an expression (class, method or interface) to guarantee that intermediate results do not vary because of implementation defined compiler optimizations or by design. This code snippet is guaranteed to return positive INFINITY because of the intermediate overflow condition.

Code Block
bgColor#ccccff
strictfp class Strictfp {
  public static void main(String[] args) {
    double d = Double.MAX_VALUE;
    System.out.println(""This value \"""" + ((d * 1.1) / 1.1) + "\""\" cannot be represented as double."");
  }
}

Risk Assessment

Not using the strictfp modifier can result in platform defined behavior with respect to the accuracy of floating point operations.

...

FLP02-J. Do not attempt comparisons with NaN            07. Floating Point (FLP)            FLP04-J. Check floating point inputs for exceptional values