There is a technical standard called IEEE 754 , which defines how the representation of the double-floating point precision. In Java, this representation is materialized in the data type double
. In other words, the representation of this technical standard is followed strictly when working with double
in Java.
As long as the JVM controls and performs operations involving double
, it is guaranteed that double precision occurs the way it should occur (following the IEEE 754 standard). However, for optimization and speed issues, it can happen that the JVM delegates these operations to the machine's processor and that is where things can get complicated because, as we know, there are several types of processors in the market, each with its architecture and features including how they deal with calculations involving floating points and do not necessarily follow the technical standard cited above. This means that there is no guarantee that the same calculation, involving the same numbers, will always generate the same precision on different processors (that is, the result is not deterministic) and this can be a problem if you, for example, have a program of mathematical application that needs extreme precision.
To ensure that a calculation with these numbers is always performed by the JVM and not delegated to the processor (thus eliminating the possibility of different results depending on the processor), the keyword will be used in the variables that will be used in this calculation
strictfp
. This ensures that, regardless of the platform on which your program runs, a floating-point calculation will be deterministic (given the same input data, the result will always be the same).
For 99.9% of developers, however, these possible differences do not matter, since most applications developed by them do not require such precision, and this explains why you hardly ever come across that keyword being used, but make no mistake, it is used rather, probably in scientific applications such as particle accelerators or even mathematical modeling.