咋就这么邪门呢?

const static MAX = 500;
// 循环体略
aPoint[i].x = nWidth*i/MAX; // OK
aPoint[i].x = (nWidth*i)/MAX;// OK
aPoint[i].x = nWidth*(i/MAX);// error
最后一条语句为什么赋的值和前两个不一样呢?!
[206 byte] By [M_Rock_Shell] at [2007-12-16]
# 1
i和MAX都是int类型
先计算除法后,丢失了精度
liushmh-想开书店: at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 2
数据精度丢失问题!
例子(安整除)
(2 * 5) / 3 = 10 / 3 = 3
2 * (5 / 3) = 2 * 1 = 2
# 3
没得说了
tlping-看不见 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 4
/是求整,你那样少了很多。你不觉得吗??
sjf331-兄弟 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 5
/是求整,你那样少了很多。你不觉得吗??
sjf331-兄弟 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 6
hehe,这样你的 结果肯定不正确!
sdx_none-穿石水滴 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 7
i=10
i / MAX =0;它是取整的
airhawk at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 8
i如果是小于50的话就为0了
johnmack-爱若琴弦 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...