FT>How do you test for integer overflow?
You don't.
Well, if you are dealing with unsigned numbers, you can check to see if
the result is smaller than the original (if you add. If you are
subtracting, it'd be larger.) For multiplication, all you could do is
do the division and make sure you got your original number.
If it's signed, you watch the signs, and/or check to see if the result
is smaller/larger than it should be.
Realistically though, there isn't any decent way to check for integer
overflow. Modern CPUs just aren't designed to do it, like FPUs do with
floating point numbers. (Well, they do have an 'overflow' flag, but
there's no portable way to get to it, you'd have to use some inline asm,
and even then, you'd have to check it after each integer operation,
since its not 'signaled' like with FPU exceptions.)
--- QScan/PCB v1.19b / 01-0162
---------------
* Origin: Jackalope Junction 501-785-5381 Ft Smith AR (1:3822/1)
|