Comment by nayuki
2 hours ago
> 32-by-32 signed (you multiply -1 by -1 and get 1, with no overflow)
Wrong. You mentally casted each operand to int16_t before subsequently casting to int32_t. The first step is unjustified.
The correct calculation according to the C standard is: (int32_t)0xFFFF * (int32_t)0xFFFF, which definitely overflows.
No comments yet
Contribute on Hacker News ↗