Re: Am I Crazy? V. simple math question.
"Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> writes:
Not sure I'm addressing your question, but the correct
(default) action in the case of unexpected arithmetic overflow
would be to abort the application (since integer primitives
don't have any equivalent of floating point's NaNs and
infinities).
Patricia Shanahan <pats@acm.org> writes:
An overflow would indicate a serious programming error, and
should be handled the same way as NullPointerException. For
almost all programs, it should cause an abort with stack trace.
I see. (Actually, I was looking for a specific example.)
However, in the Web, I also find Java code like
?
private long randomSeed = 0;
??
int random(int range) {
randomSeed = randomSeed * 1103515245 + 12345;
return (int) ((randomSeed / 65535) % range);
}
?
http://aanthill.free.fr/noframe/fr/World.java_fr.html
One might wonder whether integer overflow indicates a
serious programming error here.
Assuming that it always indicates a serious programming
error, one can imagine a debugger instrumenting java code
or class files so as to detect overflow at least during
developement, testing, and debugging.