
Why round to even integers? – Mathematica Stack Exchange - matthberg
http://mathematica.stackexchange.com/questions/2116/why-round-to-even-integers
======
tagrun
I don't remember Mathematica was ever like this, although I didn't use Round[]
much either. It does what I would expect it to do today:

[http://reference.wolfram.com/language/ref/Round.html](http://reference.wolfram.com/language/ref/Round.html)

    
    
        Round[x]
        gives the integer closest to x.

~~~
ambulancechaser
that documentation is insufficient to describe what integer 1.5 rounds to.
There are two equidistant integers. So what do you expect in this case and
what does it do, and how could you expect it to do one or the other in this
case based on that documentation?

from examples further down: Round[{0.5, 1.5, 2.5, 3.5, 4.5}] yields 0, 2, 2,
4, 4

~~~
tagrun
Except in floating point arithmetic there aren't two equidistant integers.

What I expect is, Mathematica doesn't make promises about stuff that can be
affected by an infinitesimal change, with a floating point input. I don't
think you can talk about "numbers of the form x.5" precisely with floating
point. Mathematica typically behaves differently with inputs 1/2 and 0.5, so
I'm not sure what's going here. I guess Round[] works slightly differently,
maybe tries to fractionalize the input first.

I checked, and that promise is still there actually, under Details section.

~~~
SamReidHughes
> Except in floating point arithmetic there aren't two equidistant integers.

Yes there are. 1 and 2 are equidistant from 1.5.

> I don't think you can talk about "numbers of the form x.5" precisely with
> floating point.

Yes you can.

~~~
tagrun
If only IEEE-754 math worked as infinite-precision math. You should first
learn some basics about floating point numbers before attempting to make such
strong assertions to correct people with such a bossy attitude (you're 100%
wrong BTW).

Here's a quick exercise for you:

#include <stdio.h>

int main() { float x = 123456789.5; printf("%f\n", x); return 0; }

prints 123456792.000000

And the distance between two nearest floats grow larger as you go away from 0.
So the nearest existing integers aren't 123456790 or 123456788 either.

~~~
SamReidHughes
Meanwhile, 2 - 1.5 == 1.5 - 1, and in half the integer range, the .5's can be
represented exactly.

~~~
tagrun
I think I've wasted enough time with your ignorant ramblings.

Yeah, yeah, go and live with your delusions happily ever, "pal". Shoo.

~~~
SamReidHughes
Guess what pal, even IEEE defines the round to even mode for results exactly
between two integers (when they're the nearest representable values).

------
yellowapple
I'm surprised none of the answers seem to emphasize IEEE 754, which recommends
ties-to-even rounding as the default (but allows ties-away-from-zero, which is
what's more familiar to me and probably the person who asked the question in
the first place).

