资讯专栏INFORMATION COLUMN

Java keyword: strictfp

rubyshen / 1268人阅读

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;
    }
}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/69774.html

相关文章

  • Java 关键字专题

    摘要:和也许看起来像是关键字,但是他们专门用于表示布尔类型的字面量。值得注意的是,在中整形值和布尔值之间不能相互转换至少在语言层面。相关的操作等于不等于取反位与异或或条件与条件或三目运算符在控制流程中使用一个布尔值可且仅可被转型为,类型。 总览 Java 语言中有 50 个关键字,这些关键字不能用作标识符,如下图所示(来自 jls8) showImg(https://segmentfault...

    Dogee 评论0 收藏0
  • Java关键字的笔记

    摘要:我在查询一些资料的时候,发现资料中说的关键字都不一致,而且具体的单词也都大不相同,所以我特意查阅了截止到目前最新的官方文档,对此进行了整理因为是在的时候收购的公司,所以官网上我只找到了的文档官方文档链接中中的就是对应的版本要把我在查询一些资料的时候,发现资料中说的关键字都不一致,而且具体的单词也都大不相同,所以我特意查阅了jdk6-15(截止到目前(2020.01.04)最新)的官方文档,对...

    Tecode 评论0 收藏0
  • java修饰符使用指南

    摘要:应用在修饰类名,类成员,方法,参数,构造器中。接口修饰符构造器修饰符方法修饰符字段修饰符参数修饰符最基本的修饰符作用在类上当此修饰符修饰类。作用在构造器上在构造器上,只允许使用三种修饰符,。当此修饰符修饰构造器。 1、什么是修饰符? 指的是一种标识类型以及类型成员的访问范围的声明。 应用在修饰类名,类成员,方法,参数,构造器中。 2、修饰符的有几种? ...

    elva 评论0 收藏0
  • java单词集

    摘要:集成开发工具计算机软件文件夹目录工作空间类型不匹配变量局部变量引用使用初始化赋值未定义匹配参数重复类静态的无返回值方法类体方法体系统输入输出打印运行如果或者判断或者默认循环循环循环打断继续返回私有保护公有抽象最终常量静态同步继承实现新的本 Java  eclipse idea=IDE 集成开...

    melody_lql 评论0 收藏0
  • 纪念我曾经的 JAVA 姿势

    摘要:,关闭不当编译器警告信息。创建固定大小的线程池。此线程池不会对线程池大小做限制,线程池大小完全依赖于操作系统或者说能够创建的最大线程大小。此线程池支持定时以及周期性执行任务的需求。 目前在搞 Node.js,曾经的 JAVA 知识忘了好多,为此整理了下,感叹下工业语言还是有相当的优势的。 流 Java所有的流类位于java.io包中,都分别继承字以下四种抽象流类型。 Type 字节...

    The question 评论0 收藏0

发表评论

0条评论

rubyshen

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<