1

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?

Ujjwal
  • 2,365
  • 2
  • 11
  • 7
  • 2
    Using `strictfp` in classes, interfaces and methods definitions ensures that floating-point calculations remain identical on all platforms. – Omoro Dec 09 '16 at 10:07
  • `strictfp` causes the behavior to be strict, therefore reproducible, therefore portable. When would you need portable FP arithmetic? I have no personal experience of needing this, but I hear games are one possible use case (although many people use fixed point arithmetic instead). – Theodoros Chatzigiannakis Dec 09 '16 at 10:08

1 Answers1

1

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.

Ujjwal
  • 2,365
  • 2
  • 11
  • 7
  • 1
    Answering your own question in 3 min deserves a reward:) http://stackoverflow.com/a/31394053/706695 – HRgiger Dec 09 '16 at 10:17
  • just now i checked that the difference between the time of questioning and answering my question is 10 min and not 3 min. and in 10 min lot can be read. – Ujjwal Dec 09 '16 at 10:33
  • Why you ask a question if you already know the answer? Maybe you are missing the point that this site is not for content creation. – HRgiger Dec 09 '16 at 10:41