Java 8 RFR 8010430: Math.round has surprising behavior for odd values of ulp 1
Brian Burkhalter
brian.burkhalter at oracle.com
Fri Aug 23 20:32:44 UTC 2013
With respect to this issue, the argument satisfies the condition
a == (int)a
or
a == (long)a
so there really is no tie, unless I am missing something. The problem is that in the current implementation the intermediate result
a + 0.5
is rounded according to the IEEE standard so the conditions above are no longer true.
On Aug 23, 2013, at 1:24 PM, Dmitry Nadezhin wrote:
> The specification of java.lang.Math.round() says
> * Returns the closest {@code int} to the argument, with ties
> * rounding up.
>
> It is not clarified what is "ties rounding up".
> I guess that it should correspond to the direction "roundTiesToAway" of
> IEEE 754-2008
> and to the java.math.RoundingMode.HALF_UP .
>
> They round
> +0.5 -> +1
> -0.5 -> -1
>
> The current implementation of java.lang.Math.round() rounds
> +0.5 -> +1
> -0.5 -> 0
>
> "ties rounding up" should match IEEE754 standard and other JDK math class,
> shouldn't it ?
More information about the core-libs-dev
mailing list