We will discuss about
strictfp keyword in Java.
strictfp is a keyword in the Java programming language that restricts floating-point calculations to ensure portability. The
strictfp was introduced into Java with the Java virtual machine (JVM) version 1.2 and is available for use on all currently updated Java VMs.
The IEEE standard IEEE 754 specifies a standard method for both floating-point calculations and storage of floating-point values in either single (32-bit, used in Java floats) or double (64-bit, used in Java doubles) precision.
Prior to JVM 1.2, floating-point calculations were strict; that is, all intermediate floating-point results were represented as IEEE single or double precisions only. As a consequence, errors of calculation (round-off errors), overflows and underflows, would occur with greater frequency than in architectures which did intermediate calculations in greater precision. The arithmetic issues were real problems on early Java VMs, and many other solutions besides the use of this instruction were proposed.
Since JVM 1.2, intermediate computations are not limited to the standard 32 bit and 64 bit precisions.
On platforms that can handle other representations e.g. 80-bit double extended on x86 or x86-64 platforms, those representations can be used, helping to prevent round-off errors and overflows, thereby increasing precision.
strictfp ensures that we get exactly the same results from our floating point calculations on every platform.
If you do not use
strictfp, the JVM implementation is free to use extra precision where available.
Thanks for reading.Tags: Java FAQs