I'm implementing some neural network library in java , and there are intensive double
(not Double
) matrix operations, Matrices are large and performance is required of course.
So I came to read about strictfp
keyword I honestly didn't understand what it does exactly and I was looking for simple explanation about If i should be using it or not and why
strictfp is a modifier that stands for strict floating-point which was not introduced in the base version of java as it was introduced in Java version 1.2.
strictfp is used to ensure that floating points operations give the same result on any platform. As floating points precision may vary from one platform to another. strictfp keyword ensures the consistency across the platforms.
strictfp is an obsolete and unused reserved word in the Java programming language. Previously, this keyword was used as a modifier that restricted floating-point calculations to IEEE 754 semantics in order to ensure portability.
Definition and Usage The this keyword refers to the current object in a method or constructor. The most common use of the this keyword is to eliminate the confusion between class attributes and parameters with the same name (because a class attribute is shadowed by a method or constructor parameter).
strictfp indicates that floating point calculations should use the exact IEEE754 standard. Without strictfp, the VM is free to use other (but platform dependent) representations of intermediate float and double values, in order to increase precision.
Use strictfp if you need the exact same results on multiple platforms. Avoid it if you want the best precision your current platform can give you.
E.g. in the following simple addition:
2.0 + 1.1 + 3.0
Do you want the intermediate results (e.g. 2.0 + 1.1) to be represented as an IEEE754 standard double, or with the best possible precision your platform allows. strictfp ensures the first, not using strictfp allows the VM to use the second alternative.
Not using strictfp will not hurt performance, and may on platforms where the native float types don't map to IEEE754 increase performance, since the VM isn't required to convert back and forth in between native and IEEE754 formats. The answer is platform dependent, you'll need to measure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With