strictfp

From Wikipedia, the free encyclopedia

strictfp is a Java keyword used to restrict floating-point calculations to ensure portability. The modifier was introduced into the Java programming language with the Java virtual machine version 1.2.

In older JVMs, floating-point calculations were always strict floating-point, meaning all values used during floating-point calculations are made in the IEEE-standard float or double sizes. This could sometimes result in a numeric overflow or underflow in the middle of a calculation, even if the end result would be a valid number. Since version 1.2 of the JVM, floating-point calculations do not require that all numbers used in computations are themselves limited to the standard float or double precision.

However, for some applications, a programmer might require every platform to have precisely the same floating-point behavior, even if some platforms could handle more precision. In that case, the programmer can use the modifier strictfp to ensure that calculations are performed as in the earlier versions—only with floats and doubles.

The modifier can be used in combination with classes, interfaces and methods.

Compile-time constant expressions must always use strict floating-point behavior. Other expressions use strict floating-point math if they are contained in a method, interface, or class which uses the strictfp modifier in its declaration. In a class declaration, the modifier can be placed like this:

public strictfp class MyFPclass { 
    // ... contents of class here ...
}

[edit] References