sgeos said:
I think you hit the nail on the head. What arithmetic systems does
Java operate in?
The authoritative source is the JLS. Section 15, Expressions, at
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#44393
begins with some general rules, followed by details for each combination
of type and operation.
There are two main flavors of arithmetic, integer (int and long), and
floating point (float and double). The JLS defines arithmetic for the
other integer types only in terms of conversions and int arithmetic.
The integer types both behave like 2's complement binary. It is
arithmetic modulo 2^N (Using "^" for exponentiation) where N is 32 or
64, but treated as a signed range where it matters. Addition,
subtraction, and multiplication can cause wrap-around.
Integer.MAX_VALUE+1 is equal to Integer.MIN_VALUE. Division rounds
towards zero to get an integer value.
The floating point types are, effectively, IEEE 754 32 bit and 64 bit
binary floating point. They suffer from the usual limitations of
floating point, including rounding error that can make even addition
non-associative.
Patricia