This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Document arithmetic overflow semantics


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]