Why strictfp came into existence?

306 Views Asked by At

I have always read strictfp restricts floating point calculations to IEEE-754 standard, but never read why their came the need for restricting the calculation's result according to this standard?

1

There are 1 best solutions below

3
Ujjwal On

when java was being developed by james gosling and his team, platform independency was the priority. They wanted to make oak(Java) so much better that it would run exactly same on any machine having different instruction set, even running different operating systems. But their was a problem with floating point arithmetic i.e when it came to calculation of float or double values, the arithmetic result was different on different machines (32/64 bit processor architecture) due to the precision. As some processor were built targeting efficiency(fast computation)like pentium processors of that time, while rest were targeting accuracy (accurate results) like older processors of that time.

Since processor strugling for fast computation rounded up precision values but other processor didn't, and thus the result was slightly different. And this difference was against the java slogan of WORA. Thus Java people came with the modifier strictfp which restricted the result of the floating point arithmetic to IEEE-754 standard.

Strictfp ensures that we get exactly the same results from our floating point calculations on every platform. If we don't use strictfp, the JVM implementation is free to use extra precision where available. The implication is that if we don't specify strictfp, then the JVM and JIT compiler have license to compute our floating-point calculations however they want. In the interest of speed, they will most likely delegate the computation to our processor. But With strictfp on, the computations have to conform to IEEE 754 arithmetic standards, which, in practice, probably means that the JVM will do the computation, making it possible to get the same result for floating point arithmetic on any machine.