Java keyword: strictfp

发布时间:2019-11-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Java keyword: strictfp脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

The strictfp keyword is used to force the PRecision of floating point calculations (float or double) in Java conform to IEEE’s 754 standard, explicITly. Without using strictfp keyword, the floating point precision dePEnds on target platform’s hardware, i.e. CPU’s floating point processing capability. In other words, using strictfp ensures result of floating point computations is always same on all platforms.

The strictfp keyword can be applied for classes, interfaces and methods.

Rules

strictfp cannot be applied for constructors. If an interface or class is declared with strictfp, then all methods and nested types within that interface or class are implicitly strictfp. strictfp cannot be applied for interface methods. 

Examples

The following class is declared with strictfp, hence all the floating point computations within that class conform to IEEE’s 754 standard:

strictfp class StrictFPClass {     double num1 = 10e+102;     double num2 = 6e+08;     double calculate() {         return num1 + num2;     } } 

The following interface is declared with strictfp, but its methods cannot:

strictfp interface StrictFPInterface {     double calculate();     strictfp double compute();    // compile error } 

The following method is declared with strictfp:

class StrictFPMethod {     strictfp double computetotal(double x, double y) {         return x + y;     } } 

脚本宝典总结

以上是脚本宝典为你收集整理的Java keyword: strictfp全部内容,希望文章能够帮你解决Java keyword: strictfp所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。