CKTIS / Java
strictfp — historische floating-point-striktheid
strictfp — historische floating-point-striktheid: strictfp vroeg historisch om strikte floating-point-evaluatie, maar sinds Java 17 zijn alle floating-point-expressies always-strict en verandert de modifier geen resultaten.
Versie: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
strictfpstrictfp vroeg historisch om strikte floating-point-evaluatie, maar sinds Java 17 zijn alle floating-point-expressies always-strict en verandert de modifier geen resultaten.
Java 21-broncode mag strictfp voor compatibiliteit of documentatie behouden; nieuwe code heeft het niet nodig voor reproduceerbare IEEE 754-semantiek.
De compiler kan waarschuwen dat strictfp overbodig is; het biedt geen decimale exactheid en garandeert geen identieke Math-resultaten op elk platform.
NaN, oneindigheden, signed zero en binaire afronding blijven gelden; gebruik BigDecimal met expliciete MathContext voor exacte decimalen.
De som 0.1 + 0.2 heeft reproduceerbare hexvorm 0x1.3333333333334p-2 en sqrt(-1.0) geeft NaN ondanks overbodige strictfp.
Voorbeelden
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)));
}
}
Resultaat
0x1.3333333333334p-2 true
De som 0.1 + 0.2 heeft reproduceerbare hexvorm 0x1.3333333333334p-2 en sqrt(-1.0) geeft NaN ondanks overbodige strictfp.