At the bottom, some of C's arithmetical rules
are 'stupid'.  Especially as regards type
promotion.  At least they're well-defined.

Absolutely true in a mathematical sense is that
the difference between two unsigned numbers is
SIGNED!  But that's not what C does.  You can get
around this, easy enough, but you do have to
understand exactly what is going on.  It helps
if you are working on a 2's-complement machine.

Off the cuff, I think this works:

unsigned int a, b;
int delta;
...
delta = (int)a - (int)b;
if (delta < 0) delta = (int)b - (int)a;

-or maybe-

if (delta < 0) delta = -delta;

-- Jim

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to