关键字strictfp是什么意思?

3

有人可以解释一下以下类中的关键字strictfp是什么意思吗?

public strictfp class Demo {
        public static void main(String[] args) {
                double d = 8e+307;
                /** affiche 4 * d /2 donc 2 * d */
                System.out.println(4 * d / 2);
                /** affiche 2 * d */
                System.out.println(2 * d);
        } 
}

@Karthikeyan Vaithilingam 我也发现了这个什么是strictfp修饰符?何时考虑使用它? - hulk
1个回答

5

Java的strictfp关键字确保在浮点变量上执行操作时,在每个平台上都可以得到相同的结果。 strictfp关键字可以应用于方法、类和接口。

strictfp class A{}//strictfp applied on class  
strictfp interface M{}//strictfp applied on interface  
class A{  
strictfp void m(){}//strictfp applied on method  
}  

严格浮点(strictfp)关键字不能应用于抽象方法、变量或构造函数。
class B{  
strictfp abstract void m();//Illegal combination of modifiers  
}  
class B{  
strictfp int data=10;//modifier strictfp not allowed here  
}  
class B{  
strictfp B(){}//modifier strictfp not allowed here  
} 

谢谢,但是浮点变量是什么意思? - hulk
2
@hulk,浮点变量是一种可以存储像2.6、8.430、0.086等数字的变量。基本上,它可以存储带有小数的数字。 - Box Box Box Box

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接