Am 09.03.2010 12:02, schrieb Kevin L. Stern:
I did a quick search and it appears that Java is indeed two's
complement based. Nonetheless, please allow me to point out that, in
general, this type of code worries me since I fully expect that at
some point someone will come along and do exactly what Dmytro
suggested; that is, someone will change:
if (a - b > 0)
to
if (a > b)
and the entire ship will sink. I, personally, like to avoid
obscurities such as making integer overflow an essential basis for my
algorithm unless there is a good reason to do so. I would, in
general, prefer to avoid overflow altogether and to make the overflow
scenario more explicit:
+1
I think those optimizations should be done by HotSpot.
-Ulf