3 ms·
If it can be assumed that only modern processors are that can deliver 2's-complement modulo (not saturation) results are used, then testing is easy: #defin
by errcorrectcode 5y ago
If it can be assumed that only modern processors are that can deliver 2's-complement modulo (not saturation) results are used, then testing is easy:
#define IS_UINT_SUB_UNDERFLOW (x, y) ((x) - (y) > (x))
#define IS_UINT_ADD_OVERFLOW (x, y) ((x) + (y) < (x))
#define IS_UINT_MUL_OVERFLOW (x, y, size_max) ((x) && (y) > (size_max) / (x))