[PATCH] Document arithmetic overflow semantics
Andrew Haley
aph@redhat.com
Thu Feb 13 19:32:00 GMT 2003
Robert Dewar writes:
> > What do you mean by this, exactly? Java is defied as having signed
> > two's complement arithmetic.
>
> At the implementation level, the difference between signed and unsigned
> arithmetic (for operations like plus and minus) is in whether overflow
> is an issue or not (look for example at the MIPS). The issue of "2-s complement"
> just has to do with how you interpret a bit pattern (i.e. whether all 1's is
> a big number of minus one). If you have wrap around semantics, then, regardless
> of how you choose to interpret the bit patterns, the appropriate run-time
> representation of add/subtract operations is to do unsigned adds with no
> carry around (and no signed overflow detection).
Obviously, but you said
> it seems clear that Java should be using unsigned arithmetic for
> all operations, since that is the way Java is defined.
and clearly this is in incorrect in many cases, for example int->long
conversion and indeed anything that involves integer operands of
different sizes.
Andrew.
More information about the Gcc
mailing list