【发布时间】:2013-11-11 08:48:29
【问题描述】:
int isOverflow(uint a, uint b) {
// a and b are unsigned non-zero integers.
uint c = a * b;
if (c < ( a > b ? a : b))
return 1;
else
return 0;
}
我错过了什么吗?我认为上面的 sn-p 会起作用。
EDIT :我见过像multiplication of large numbers, how to catch overflow 这样的其他解决方案,它使用一些花哨的方法来检查它。但对我来说,上面的简单解决方案看起来也是正确的。这就是我问这个问题的原因。
【问题讨论】:
标签: c overflow multiplication