lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> >If the machine does not use two complement, doing arithmetic over
> >unsigned versions of signed integers will not give the correct results
> >anyway (this is the privilege of two-complement arithmetic), so the
> >conversion back to signed is the least of the problems.
> I'm not sure I can follow, but arithmetic on unsigned integers
> always behaves like two's complement arithmetic, [...]

Exactly. So, if the machine does not use two complement arithmetic,
this behavior will not be the correct one for (the machine's) signed

Simple example: Assume a machine using sign-and-magnitude (I will use
only four bits to simplify); then we do 3+(-2)=1. In sign-and-magnitue,
this becomes 0011+1010=0001. However, if we do the computation with
unsigneds, we have 0011+1010=1101, the wrong answer.
-- Roberto