我用下面的方法在Windows 8(英特尔凌动Z3775):Strictfp返回在不同的系统不同的结果
public static strictfp void main(String args[])
{
float a = 0.000000002f;
float b = 90000300000000004f;
float c = a * b;
System.out.println(c);
}
这给了我:1.80000592E8
在运行时
public strictfp void calculate()
{
float a = 0.000000002f;
float b = 90000300000000004f;
float c = a * b;
Toast.makeText(getApplicationContext(), c + "", Toast.LENGTH_LONG).show();
}
我得到:1.8000059E8
他们为什么不同?我使用strictfp错了吗?
如果在两种情况下都输出String.format(“%08x”,Float.floatToIntBits(c)),会发生什么? –
它们返回完全相同的字符串。在两个平台上使用Float.toString(c)转换为String不会有帮助。 – Geosearchef
对 - 所以实际的数字是按位相同的。在将浮动转换为字符串的算法的实现方面存在简单的差异。 –