3 ms·
Sarcarsm? In some cases you can just do sanity checks on your inputs and use larger number formats for doing sums. Depends on the use case.
by tomovo 10y ago
Sarcarsm? In some cases you can just do sanity checks on your inputs and use larger number formats for doing sums. Depends on the use case.
- jandrese 10y agoYou would also be hard pressed to find a modern architecture that doesn't use twos complement for signed integers. That said, rolling over on a signed integer is almost always an error, although luckily it is usually one of the easier ones to detect in the debugger. Big negative numbers are a dead giveaway.
- dispose13432 10y agoIt's easy to detect in the debugger. The danger is signed int x; cin>>x; if(x+1<x){return OVERFLOW;} will, in modern optimizing compilers, never return OVERFLOW There were quite a few security holes introduced by the compiler with that. ----- The only problem is to make a standard, one has to define that MAX_INT+1 = 0 or something. Then, whenever one does signed int x; cin>> x; signed int y = x+1; really turns into signed int = 0; if ( x < MAX_INT) y= x+1 else y = 1;