Java Reference
In-Depth Information
or underflows that would occur if the arithmetic were executed strictly.
This means that some applications may run differently on different vir-
tual machines when under non-strict floating point. Non-strict floating
point might also execute faster than strict floating point, because the
relaxed rules may allow the use of representations that are supported
directly by the underlying hardware.
The strictness of floating-point arithmetic is determined by the presence
of the modifier strictfp , which can be applied to a class, interface, or
method. When you declare a method strictfp , all the code in the meth-
od will be executed according to strict constraints. When you use strict-
fp on a class or interface, all code in the class, including initializers
and code in nested types, will be evaluated strictly. To determine if an
expression is strict, all methods, classes, and interfaces within which
the expression is contained are examined; if any of them is declared
strictfp then the expression is strict. For example, an inner class de-
clared within a strict outer class, or within a strict method, is also strict.
However, strictness is not inheritedthe presence of strictfp on a class
or interface declaration does not cause extended classes or interfaces to
be strict.
Constant expressions that require floating point are always evaluated
strictly. Otherwise, any code that is not marked as strictfp can be ex-
ecuted under rules that do not require repeatable results. If you want
to guarantee bit-for-bit exact results across all Java virtual-machine im-
plementations, you should use strictfp on relevant methods, classes,
and interfaces. You should also note that a virtual machine can satisfy
the rules for non-strict floating point by always acting strictly: Non-strict
floating point does not require the virtual machine to act differently, it
offers the virtual machine a degree of freedom to optimize code where
repeatable results are not required.
Non-strict floating-point execution allows intermediate results within ex-
pressions to take on values with a greater range than allowed by the
usual float or double representations. These extended range represent-
ations avoid some underflows and overflows that can happen with the
standard representations. Fields, array elements, local variables, para-
meters, and return values always use the standard representations.
 
Search WWH ::




Custom Search