|
|
|
|
|
by symmetricsaurus
1294 days ago
|
|
There’s no reason to expect the result of integer overflow to be negative, or any particular value at all. It is undefined. So after checking that x > o there is no way for i (a product and ratio of positive numbers) to become negative. The only reason this is surprising is that there is an expectation of wrapping on overflow. But this is simply not the behavior of the C virtual machine. (Maybe today it makes sense to have even C wrap in a two’s-complement way? C is used in many places though, maybe there are still platforms in use that aren’t two’s-complement?) |
|