what optimizations are invalid in java?
Robert Dewar
dewar@gnat.com
Wed Mar 13 06:56:00 GMT 2002
<<Only divide by zero. Basically, Java does whatever SPARC UNIX
happened to do at the time. This is not, I suspect, a coincidence...
>>
I think that's probably unfair. Division by zero is obviously reasonable
to consider as an error, one cannot imagine any program expecting something
useful from divide by zero (though I hesitate to say such things are the
adamant support for the utility of self-initializations :-)
But when it comes to artithmetic overflow, there are two issues to consider
1. efficiency, testing for overflow in all signed arithmetic operations is
not free.
2. expected functionality. many C programmers expect and count on wrap around
semantics for signed arithmetic even though it is not defined.
In Java, signed arithmetic had to be made always wrap around, or always
checking. Now I would have gone for always checked, but I understand the
arguments for wrap around.
More information about the Java
mailing list