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?

- 688
- 9
- 33
2 Answers
As of Java 17 and JEP 306, you wouldn't use it:
Make floating-point operations consistently strict, rather than have both strict floating-point semantics (
strictfp
) and subtly different default floating-point semantics.[T]he SSE2 (Streaming SIMD Extensions 2) extensions, shipped in Pentium 4 and later processors starting circa 2001, could support strict JVM floating-point operations in a straightforward manner without undue overhead.
Since Intel and AMD have both long supported SSE2 and later extensions which allow natural support for strict floating-point semantics, the technical motivation for having a default floating-point semantics different than strict is no longer present.
See also JLS §8.4.3.5:
The
strictfp
modifier on a method declaration is obsolete and should not be used in new code. Its presence or absence has has no effect at run time.
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 strictfp
modifier.
public class Strictly {
public strictfp double calc(double d1, double d2) {
return d1 * d2;
}
}
$ 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

- 285,553
- 42
- 434
- 765

- 15,432
- 2
- 42
- 54
-
Sir then in the next release of java(18), will `strictfp` be deprecated? – Arsh Coder Oct 09 '21 at 05:16
-
@JFan I'm not sure. In a sense, it's deprecated now, since it's use produces a compiler warning, but I don't know if they are planning on doing anything more. – David Conrad Oct 09 '21 at 16:29
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

- 21
- 4