Strictfp in Java

I have implemented some neural network libraries in Java, and there are tight double (not double) matrix operations. The matrix is large, and of course, performance is required

So let me look at the keyword about strictfp. I really don't understand what is correct. I'm looking for a simple explanation. If I should use it, why

Solution

Strictfp indicates that the precise IEEE 754 standard should be used for floating point calculation Without strictfp, VM is free to use intermediate floating point numbers and other (but platform dependent) representations of double values to improve accuracy

If you need identical results on multiple platforms, use strictfp If you want the best accuracy your current platform can provide, avoid this problem

For example In the following simple supplement:

2.0 + 1.1 + 3.0

Do you want to express intermediate results (e.g. 2.0 1.1) as double the IEEE754 standard, or with the best accuracy allowed by your platform Strictfp ensures that the first one is not used, and allows the VM to use the second alternative

Not using strictfp will not affect performance, and may improve performance on platforms where local floating-point types are not mapped to IEEE754, because VM does not need to convert back and forth between local and IEEE754 formats The answer depends on the platform and you need to measure

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>