看sun公司网上的教程:
有一段话如下:
(Hint: Generally, you shouldn't use the equality operator, ==, with floating-point numbers since floating-point numbers by nature are difficult to match exactly.
Instead, test whether the number is close to zero.) 有了以下问题:
1.为什么判断浮点数是否为0不能直接通过==比较。(详细说明)2.详细阐述一下浮点数的其他比较: < > and ==
有一段话如下:
(Hint: Generally, you shouldn't use the equality operator, ==, with floating-point numbers since floating-point numbers by nature are difficult to match exactly.
Instead, test whether the number is close to zero.) 有了以下问题:
1.为什么判断浮点数是否为0不能直接通过==比较。(详细说明)2.详细阐述一下浮点数的其他比较: < > and ==
float为基本类型
浮点数是有精度的,不是一个确切数,float x = 0 时,x 的实际值可能为 0.00000012.详细阐述一下浮点数的其他比较: < > and ==
我一般用 (x-0)> 0.00...1 && (x - 0) < 0.00...1 来判断是否相等
float是有效位+指数 构成的。
难道float参与比较时,会用到有效位后面的数吗?