This is a bug in Java, and not in DrJava. You can verify it
by dropping your code into a class, compiling it from the
command line, and running it-- you will get the same result.
I'm looking for some references to this behavior on the web
right now, but I'm not finding any. I also tested this with
"Math.pow(5, 23) % 5", which should obviously return 0.0 but
returns 4.0. Seems that's near the threshold, because
Math.pow(5, 22) works fine, but any larger exponents start
acting strange. (Even though Double.MAX_VALUE is 1.8E308.)
I'll see if I can find any more information about it, or
else perhaps a bug can be filed with Sun.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Actually, this isn't even a bug in Java. Another developer
pointed out that double-precision numbers (per the IEEE
spec) have 53 significant bits of precision. 5^23 requires
54 bits, so there isn't enough precision to determine a
correct modulus.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=429731
This is a bug in Java, and not in DrJava. You can verify it
by dropping your code into a class, compiling it from the
command line, and running it-- you will get the same result.
I'm looking for some references to this behavior on the web
right now, but I'm not finding any. I also tested this with
"Math.pow(5, 23) % 5", which should obviously return 0.0 but
returns 4.0. Seems that's near the threshold, because
Math.pow(5, 22) works fine, but any larger exponents start
acting strange. (Even though Double.MAX_VALUE is 1.8E308.)
I'll see if I can find any more information about it, or
else perhaps a bug can be filed with Sun.
Logged In: YES
user_id=429731
Actually, this isn't even a bug in Java. Another developer
pointed out that double-precision numbers (per the IEEE
spec) have 53 significant bits of precision. 5^23 requires
54 bits, so there isn't enough precision to determine a
correct modulus.