The round() function used in that function comes from the C math standard library. Here is an implementation that is used if it isn't available. https://github.com/python/cpython/blob/a10d426bab66a4e1f20d5e1b9aee3dbb435cf309/Python/pymath.c#L72
Aaron Meurer On Wed, Apr 10, 2019 at 6:39 PM Aaron Meurer <asmeu...@gmail.com> wrote: > > Here is the Python implementation > https://github.com/python/cpython/blob/a10d426bab66a4e1f20d5e1b9aee3dbb435cf309/Objects/floatobject.c#L917 > > It's possible you have found a bug in Python's round. I'm unclear how > it is supposed to work. > > Aaron Meurer > > On Wed, Apr 10, 2019 at 6:28 PM Aaron Meurer <asmeu...@gmail.com> wrote: > > > > Doesn't Python do rounding based on the binary representation of the float? > > > > I'm a little confused what "round to even" means in that case. > > > > Aaron Meurer > > > > On Wed, Apr 10, 2019 at 6:16 PM Chris Smith <smi...@gmail.com> wrote: > > > > > > Python 3 implements "round to even on tie" logic so `round(12.5)` -> 12, > > > not 13. I have updated, in #16608, the round function but there is a > > > difference in how ties are detected. I shift the desired position to the > > > ones position and then check for a tie so 12.345 is shifted to 1234.5 and > > > rounded to 1234 then is divided by 100 to give 12.34. Python doesn't do > > > this. I suspect it adds 0.05 and then detects that12.395 > 12395/1000 and > > > rounds up to 12.35 > > > > > > > > > >>> Rational(*.345.as_integer_ratio())-Rational(345,1000) # .345 < > > > >>> 345/1000 > > > -3/112589990684262400 > > > >>> Rational(*.395.as_integer_ratio())-Rational(395,1000) # .395 > > > > >>> 395/1000 > > > 1/56294995342131200 > > > > > > > > > >>> round(12.345,2) # 12.345 rounds up b/c a tie is not detected > > > 12.35 > > > > > > > > > > > > Does anyone have objections to the proposed rounding? > > > > > > /c > > > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "sympy" group. > > > To unsubscribe from this group and stop receiving emails from it, send an > > > email to sympy+unsubscr...@googlegroups.com. > > > To post to this group, send email to sympy@googlegroups.com. > > > Visit this group at https://groups.google.com/group/sympy. > > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/sympy/a84085c6-aa90-437c-b063-a87f909beac4%40googlegroups.com. > > > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2Bxag-303rzjyy4AF7yszngvyVM5W%3DFKtM4BZUzZBUf-A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.