strictfp 精确浮点数的计算

//在声明的范围内,所有浮点数的计算都是精确的,当类被strictfp修饰是,所有方法默认也被strictfp修饰
strictfp class MyClass {
public static void main(String[] args)
{
float aFloat = 0.6710339f;
double aDouble = 0.04150553411984792d;
double sum = aFloat + aDouble;
float quotient = (float)(aFloat / aDouble);
System.out.println("float: " + aFloat);
System.out.println("double: " + aDouble);
System.out.println("sum: " + sum);
System.out.println("quotient: " + quotient);
}
}
//float: 0.6710339
//double: 0.04150553411984792
//sum: 0.7125394529774224
//quotient: 16.167336

你可能感兴趣的:(java)