This question is not a duplicate of this question. I know that the strictfp keyword in java is used for this purpose. But How can we use this in a real life application. What are its advantages?
How can we use the strictfp method in a real life pogram?
536 Views Asked by Arsh Coder At
2
There are 2 best solutions below
0
On
strictfp in java is used to produce same result irrespective of platform when you are dealing with floating point number.
Precisions may differ on different platform due to hardware's capability for processing it. So it it insures that when the code is executed on different platform the output should not be manipulated due to different precisions.
Some Advantages are,
- Provides accuracy on various machine
- Result unbiased to hardware architecture
As of Java 17 and JEP 306, you wouldn't use it:
See also JLS §8.4.3.5:
As of the latest LTE release of Java, there is no longer any difference in semantics and there is a new compiler warning for the use of the
strictfpmodifier.$ javac Strictly.java Strictly.java:2: warning: [strictfp] as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required public strictfp double calc(double d1, double d2) { ^ 1 warning