4 ms·
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.wolfra
by tagrun 10y ago
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 10y agothat 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
- deleted 10y ago[deleted]
- tagrun 10y agoExcept 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 10y ago> 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 10y agoIf 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 10y agoMeanwhile, 2 - 1.5 == 1.5 - 1, and in half the integer range, the .5's can be represented exactly.
- tagrun 10y agoI think I've wasted enough time with your ignorant ramblings. Yeah, yeah, go and live with your delusions happily ever, "pal". Shoo.
- SamReidHughes 10y agoGuess what pal, even IEEE defines the round to even mode for results exactly between two integers (when they're the nearest representable values).