itoa'd you so?

Steve smorrey at gmail.com
Fri Sep 21 16:16:33 MDT 2007


So does this presnet a real world bug, or would the user just perform
some bounds checking prior to handing it off to the function?
Something like...

if(myval < 0 && abs(myval) == myval)

or maybe

if(myval == INT_MIN)

On 9/21/07, Dave Smith <dave at thesmithfam.org> wrote:
> Levi Pearson wrote:
> > The answer lies in 2's complement binary representation of integers.
> > There aren't the same number of integers to the left and to the right
> > of 0; there's one more to the left.  So, the absolute value of the
> > smallest representable integer isn't representable in the same number
> > of bits.
> >
>
> Yup, so in other words abs(INT_MIN) returns INT_MIN because it wraps
> around. :)
>
> Nice work Levi, and a good explanation.
>
> --Dave
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>



More information about the PLUG mailing list