logic in Math.nextAfter for handling -0.0 input
Deneau, Tom
tom.deneau at amd.com
Mon Jun 23 20:33:46 UTC 2014
The JDK method Math.nextAfter contains the logic shown below to handle an input of -0.0
When the graal compiler compiles this for the hsail backend, it makes the reasonable
assumption that "start + 0.0d" can be reduced to "start" which is a problem for this algorithm.
>From what I could tell, c2 or graal for amd64 backend do not do this optimization
and so get the right answer for -0.0 input. How do they know not to do this optimization?
} else { // start > direction or start < direction
// Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
// then bitwise convert start to integer.
long transducer = Double.doubleToRawLongBits(start + 0.0d); <==============
if (direction > start) { // Calculate next greater value
transducer = transducer + (transducer >= 0L ? 1L:-1L);
} else { // Calculate next lesser value
....
-- Tom
More information about the graal-dev
mailing list