Java 8 RFR 8010430: Math.round has surprising behavior for odd values of ulp 1

Brian Burkhalter brian.burkhalter at
Fri Aug 23 21:11:18 UTC 2013

This is an interesting point and roundToIntegralTiesToAway() does have an appealing symmetry, but I think it is a broader issue than the constrained case I originally posted.

Whichever of the approaches obtains, it seems that if the floating point argument A represents a real number which is also in the space of integers (Z), then one would expect round(A) to equal A. I think this is what most programmers would expect. For what it's worth, this is what appears to be implemented in the C language (GCC 4.2.1).


On Aug 23, 2013, at 1:44 PM, Dmitry Nadezhin wrote:

> I guess that the method java.lang.Math.round() should correspond to
> roundToIntegralTiesToAway of the IEEE 754-2008. Standard says about it
> (section 5.9):
> ===
> roundToIntegralTiesToAway(x) rounds x to the nearest integral value, with
> halfway cases
> rounding away from zero
> ===
> So the halfway cases are n + 0.5 ( like -1.5, -0.5, +0.5, +1.5).
> Standard says that roundToIntegralTiesToAway rounds them to (-2,-1,+1,+2).

More information about the core-libs-dev mailing list