问题描述
可以请某人解释为什么我收到消息框?
我该死的舒尔500除以300不等于零; -\
__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if(ufFactor == 0)AfxMessageBox(" 0")
can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\
__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");
推荐答案
什么是未签名的浮动?
-
Ian Collins。
What''s an unsigned float?
--
Ian Collins.
什么是未签名的浮动?
-
Ian Collins。
What''s an unsigned float?
--
Ian Collins.
是的,我的编译器没有编译的无符号浮点数。
yes, unsigned float that is not compiling on my compiler.
无论如何,这不是500/300。
是300/500。应该导致0.6如果ufFactor是浮动的那么。
如果是积分则为0。
- Murali Krishna
any way, that''s not 500 / 300.
it is 300 / 500. Should lead to 0.6 if ufFactor is float.
and 0 if it is integral.
-- Murali Krishna
unsigned float?
无论如何,似乎ufFactor(应该具有值300.0 / 500)
在被比较之前被转换为int(因此,舍入为0)。
尝试:
if(ufFactor = = 0.0)AfxMessageBox(0);
这是一个棘手的比较,与双打(和浮点数)比较
受制于大量四舍五入造成的问题。你应该看一下
这个列表,siblig list comp.lang.c ++。moderated和cousin lists
comp.lang.c和comp.lang.c.moderated关于浮点比较
问候,
Zara
unsigned float?
Anyway, it seems thta ufFactor (which should have the value 300.0/500)
is converted to int (thus, rounded to 0) before being compared.
Try :
if (ufFactor == 0.0) AfxMessageBox("0");
This is an tricky comparison, as comparison with doubles (and floats)
is subject to lots of problems due to rounding. You should take a look
at this list, siblig list comp.lang.c++.moderated and cousin lists
comp.lang.c and comp.lang.c.moderated about floating point comparisons
Regards,
Zara
这篇关于分裂...奇怪的行为,我不明白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!