# FP Strict ??

R K Singh
Ranch Hand
Posts: 5384
Hi there
I was going through JLS Value set conversion.
and after that I am slightly confused.
if an expression is FP-strict then expression will never evaluates in Flaot.POSITIVE_INFINITY or Double.POSITIVE_INFINITY ??
what does it mean by overflow/underflow in float. If a positive float number is added with a number which exceeds max limit of result then result will be negative in case of FP-strict expression ??
can anyone plz more elaborate abt Value set conversion.
TIA
------------------
Regards
Ravish

Jose Botella
Ranch Hand
Posts: 2120
Hi Ravish

if an expression is FP-strict then expression will never evaluates in Flaot.POSITIVE_INFINITY or Double.POSITIVE_INFINITY ??

No, it is not like that read below

from JLS 4.3
Every implementation of the Java programming language is required to support two standard sets of floating-point values, called the float value set and the double value set . In addition, an implementation of the Java programming language may support either or both of two extended-exponent floating-point value sets, called the float-extended-exponent value set and the double-extended-exponent value set . These extended-exponent value sets may, under certain circumstances, be used instead of the standard value sets to represent the values of expressions of type float or double (�5.1.8, �15.4).

The number of bits for the exponents in the float and double value set are 8 and 11. While 11 and more, and 15 and more, are for the "extended" value set fot float and double respectively.

Overflow ocurrs is a number is greater than the value set. Float/Double.POSITIVE/NEGATIVE_INFINITY represents any values that are too big for a value set.
Underflow ocurrs is a number is two small for being represented in a value set. Zero or a denormalized number represent them.

from JLS 15.4

Within an FP-strict expression, all intermediate values must be elements of the float value set or the double value set, implying that the results of all FP-strict expressions must be those predicted by IEEE 754 arithmetic on operands represented using single and double formats. Within an expression that is not FP-strict, some leeway is granted for an implementation to use an extended exponent range to represent intermediate results; the net effect, roughly speaking, is that a calculation might produce "the correct answer" in situations where exclusive use of the float value set or double value set might result in overflow or underflow.

An expression is FP-strict if ocurrs wihtin a class, interface, or method that holds the strictfp modifier, or it is a constant expresion as defined in JLS 15.28
The advantage of non FP-strict expressions is performance: they could utilize some floating point arithmethic available in moderm microprocessors.

R K Singh
Ranch Hand
Posts: 5384

Thanks Jose !!
------------------
Regards
Ravish