CKTIS / Java
strictfp — historical floating-point strictness
strictfp — historical floating-point strictness: strictfp historically requested strict floating-point evaluation, but since Java 17 all floating-point expressions are always-strict, so the modifier does not change results.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
strictfpstrictfp historically requested strict floating-point evaluation, but since Java 17 all floating-point expressions are always-strict, so the modifier does not change results.
Java 21 source may retain strictfp for compatibility or documentation, but new code does not need it for reproducible IEEE 754 expression semantics.
A compiler may warn that strictfp is unnecessary; it does not provide decimal exactness or guarantee identical Math library results on every platform.
NaN, infinities, signed zero, and binary rounding still apply; use BigDecimal with an explicit MathContext for exact decimal-domain requirements.
The sum 0.1 + 0.2 has reproducible hex form 0x1.3333333333334p-2, and sqrt(-1.0) is NaN regardless of redundant strictfp.
Examples
public class Main {
strictfp static double sum() {
return 0.1 + 0.2;
}
public static void main(String[] args) {
System.out.println(Double.toHexString(sum()));
System.out.println(Double.isNaN(Math.sqrt(-1.0)));
}
}
Result
0x1.3333333333334p-2 true
The sum 0.1 + 0.2 has reproducible hex form 0x1.3333333333334p-2, and sqrt(-1.0) is NaN regardless of redundant strictfp.