> > |
You may want to check out Javolution and JScience for some nifty ideas.
Particularly LargeInteger? (in JScience), and some other stuff in there.
I think the idea of using a long for multiplication is good (i.e. result = (long)a * b), then you can do a simple overflow = (result != (int)result). For addition/subtraction, basically, you just have to check that the sign bit (i.e. MSB) is the same as one of the operators. So for result = a + b, overflow = ( (result >> 31 != a >> 31) && (result >> 31 != b >> 31) ) -- MotiN - 17 Jan 2005 |