TN 发帖数: 1870 | 1 I know it is dangerous to test the equality of two float numbers directly.
But in some scenarios, could we use ==,
say,
float a = 1.231238f;
float b = a;
....
if (a == b) { // b got its value from assignment
...
}
else {
...
}
I have this question because sometimes, I do need to test.
Dose the compile guarantee a == b in this case (by assignment) or not? | N***m 发帖数: 4460 | 2 a==b 要使不对的话,c就有大bug了。
再怎么round off也得是一个确定的规则吧,要不然是random的话可不就乱套了?
【在 TN 的大作中提到】 : I know it is dangerous to test the equality of two float numbers directly. : But in some scenarios, could we use ==, : say, : float a = 1.231238f; : float b = a; : .... : if (a == b) { // b got its value from assignment : ... : } : else {
|
|