I read the JVM specification for the fpstrict
modifier but still don't fully understand what it means.
Can anyone enlighten me?
I read the JVM specification for the fpstrict
modifier but still don't fully understand what it means.
Can anyone enlighten me?
Basically, it mandates that calculations involving the affected float
and double
variables have to follow the IEEE 754 spec to the letter, including for intermediate results.
This has the effect of:
Edit:
More specifically, many modern CPUs use 80 bit floating point arithmetic ("extended precision") internally. Thus, they can internally represent some numbers in denormalized form that would cause arithmetic overflow or underflow (yielding Infinity or zero, respectively) in 32 or 64bit floats; in borderline cases, 80 bit just allows to retain more precision. When such numbers occur as intermediate results in a calculation, but with an end result inside the range of numbers that can represented by 32/64bit floats, then you get a "more correct" result on machines that use 80bit float arithmetic than on machines that don't - or in code that uses strictfp
.
I like this answer, which hits the point
It ensures that your your calculations are equally wrong on all platforms.
strictfp is a keyword and can be used to modify a class or a method, but never a variable. Marking a class as strictfp means that any method code in the class will conform to the IEEE 754 standard rules for floating points. Without that modifier, floating points used in the methods might behave in a platform-dependent way. If you don't declare a class as strictfp, you can still get strictfp behavior on a method-by-method basis, by declaring a method as strictfp. If you don't know the IEEE 754 standard, now's not the time to learn it. You have, as we say, bigger fish to fry.