Java Keywords (Part XX): The strictfp
Keyword
Java keyword list
abstract | continue | for | new | switch |
assert | default | goto* | package | synchronized |
boolean | do | if | private | this |
break | double | implements | protected | throw |
byte | else | import | public | throws |
case | enum | instanceof | return | transient |
catch | extends | int | short | try |
char | final | interface | static | void |
class | finally | long | strictfp | volatile |
const* | float | native | super | while |
Prior to Java 17, this keyword was used to establish a strict floating-point (strict fp) policy. This meant that, when in use, this keyword guaranteed that floating point calculations would yield the same result across all hardware. When not in use, the Operating System had some leeway in refining precision of floating-point calculations. The keyword would be applied at the class, interface, or method. Since this is no longer the case with x86 architecture, Java 17 inherently does all floating point calculations in accordance with IEEE-754.
In summary, different computer architectures were designed to handle floating point calculations for precision (strict) or for efficiency or speed (non strict). Becuase these differences in philosophies, porting Java across multiple platforms meant that floating point calculations were not guaranteed to yield the same results unless strictfp
was used. Since modern computer architectures don't need x87 chips for these calculations, non-strict calculations are no longer needed.
public strictfp class MyCalculator {
// Your code here
}
public class SomeClass {
public strictfp double calculateSomething(double x, double y) {
// DO some calculation
}
}
Next up, Part XXI: synchronized
Comments
Post a Comment