Numeric Comparator overflows.
Brought to you by:
vittek
Hiya, Have just started using SGLIb and like plenty,
one small problem I've had is with the standard numeric
comparator:
#define SGLIB_NUMERIC_COMPARATOR(x, y) ((int)((x) - (y)))
It's easy to overflow, leading to incorrect results
(sometimes) e.g.
printf("%d",SGLIB_NUMERIC_COMPARATOR_OLD(INT_MIN,INT_MAX));
Something like this works better (I think):
#define COMPARATOR(x, y) ((int)((x==y)?0:(x>y)?1:-1))
Logged In: YES
user_id=53477
Hi,
many thanks for reporting the problem. I have considered my
solution so beautifull and fast and did not think about the
overflow problem :) I will look for some fast and correct
definition of this comparator and will change the default
definition.
Best regards,
Marian