Math.round(...) and bug 6430675

Jeff Hain jeffhain at
Thu Jan 31 21:26:20 UTC 2013


Since 6430675 fix, Math.round(float) and Math.round(double)
specs no longer specify rounding by adding 0.5 and then using floor,
and let the user believe that they "now round up properly".

However playing with fresh JDK 7 and 8 versions I saw that
these methods still exhibit some suprising results coming
from adding 0.5 and then using floor.
For example, for odd values in [8388609.0f,16777215.0f] or
[-16777215.0f,-8388609.0f], which are mathematical integers,
Math.round(float) returns value+1.

Shouldn't the references to floor(value+0.5(f/d)) be restored
in the specs, or the implementations having a work-around for
these cases?


More information about the core-libs-dev mailing list