There is a technical standard called IEEE 754, which defines how the double precision is to be represented in practice in floating point. In Java, this representation is materialized in the data type double
. In other words, the representation of this technical standard is followed to the letter when working with double
in Java.
When and when the JVM controls and performs operations involving double
, there is a guarantee that double precision occurs the way it should occur (follows IEEE 754). However, for reasons of optimization and speed, it can happen that the JVM delegate these operations to the processor of the machine and that is where things can get complicated because, as we know, there are several types of processor in the market, each with its specific architecture and characteristics, including how they deal with calculations involving floating points and that do not necessarily follow the aforementioned technical standard. This means that there is no guarantee that the same calculation, involving the same numbers, will always generate the same accuracy on different processors (i.e., the result is not deterministic) and this can be a problem if you, for example, it has a mathematical application program that requires extreme precision.
To ensure that a calculation with these numbers is always performed by the JVM and not delegated to the processor (then eliminating the possibility of different results depending on the processor), the keyword is 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 eventual differences don’t matter, since most of the applications they develop don’t require such accuracy, and this explains why you can hardly see this keyword being used, but make no mistake, it is used yes, probably in scientific applications, such as particle accelerators or even mathematical modeling.
I had seen this answer but did not clarify all my doubts. I edited the question.
– ayowole agbedejobi
Related: https://answall.com/q/455/64969 I removed my closing vote due to the edition, which made it clear that another point was
– Jefferson Quesado