由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a question about float numbers
相关主题
如何 initialize array member?pointer to override function?
c++ 中如何把str转换为float?问个土问题:什么是satellite data?
请教关于float的精度和比较有关objec access path的问题
请教express create session的问题请教一个c++概率小程序
C的问题,高手请指点问几个问题
《Inside Windows Debugging》英文文字版/EPUB[PDF]有没有什么简单的方法从一个double precision的floating point 中读出一个特定的bit?
haskell vs java 速度一个小问题
小team政治scenarioJava read/write binary floating point data files?
相关话题的讨论汇总
话题: float话题: numbers话题: question话题: assignment话题: test
进入Programming版参与讨论
1 (共1页)
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 {

1 (共1页)
进入Programming版参与讨论
相关主题
Java read/write binary floating point data files?C的问题,高手请指点
another simple question《Inside Windows Debugging》英文文字版/EPUB[PDF]
关于gdb的问题, 谢谢haskell vs java 速度
HOW TO round float numbers to integer? in C小team政治scenario
如何 initialize array member?pointer to override function?
c++ 中如何把str转换为float?问个土问题:什么是satellite data?
请教关于float的精度和比较有关objec access path的问题
请教express create session的问题请教一个c++概率小程序
相关话题的讨论汇总
话题: float话题: numbers话题: question话题: assignment话题: test