Nice TWiki > Dev > CheckedIntegerArithmetic (r1.11 vs. r1.12) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Dev . { Changes | Index | Search | Go }
 <<O>>  Difference Topic CheckedIntegerArithmetic (r1.12 - 17 Jan 2005 - MotiN)
Added:
>
>

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


Topic CheckedIntegerArithmetic . { View | Diffs | r1.12 | > | r1.11 | > | r1.10 | More }
Revision r1.11 - 30 Dec 2003 - 18:35 GMT - BrianSlesinsky
Revision r1.12 - 17 Jan 2005 - 20:08 GMT - MotiN
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.