Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: remediation cost

...

The strictfp modifier can be used with a class, method, or interface:

Usage

Applies to

Class

All code in the class (instance, variable, static initializers), and code in nested classes

Method

All code within the method

Interface

All code in any class that implements the interface

An expression is FP-strict when any of the containing classes, methods, or interfaces is declared to be strictfp. Constant expressions containing floating-point operations are also evaluated strictly. All compile-time constant expressions are by default FP-strict.

...

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

NUM06NUM53-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.

...

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

Rule

Severity

Likelihood

Remediation Cost

Detectable

Repairable

Priority

Level

NUM06

NUM53-J

low

Low

Unlikely

unlikely

No

high

No

P1

L3

Related Guidelines

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

...


...