不确定如何判断是否可能发生溢出。我得到了这个示例代码:
char x;
float f, g;
// some values get assigned to x and f here...
g = f + x;
有人可以解释一下吗?
最佳答案
float
,在其最高限制(二进制指数为 127)下,没有足够的精度(23 位)来显示最大可能的 char
的差异( 127, 7 位),因此不可能发生溢出,因为加法不会产生任何影响(需要 127-7=120 的精度)。
关于char 或 float 溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5932336/