Strange round behavior

70 views
Skip to first unread message

Duane Nykamp

unread,
Sep 2, 2014, 8:28:31 AM9/2/14
to sy...@googlegroups.com
Is this the intended result of rounding to one decimal place?  Sympy needs to go back to school on rounding. :)

In [13]: S(0.06).round(1)
Out[13]: 0.e-1

Aaron Meurer

unread,
Sep 2, 2014, 9:03:18 PM9/2/14
to sy...@googlegroups.com
I think it's a bug with the printer. S(0.06).round(1) == 0.1 gives
True. Can you open an issue for it?

Aaron Meurer
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/e363eaad-720d-4fe6-8bce-06bafe431c3a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Sep 3, 2014, 11:01:02 AM9/3/14
to sy...@googlegroups.com
I think it's a corner case in terms of how the result is given precision. It's off by 1 in this case. And being off by one doesn't affect the boolean:

```
>>> Float('.1',0)==.1
True
>>> Float('.1',1)==.1
True
```

Chris Smith

unread,
Sep 3, 2014, 9:32:34 PM9/3/14
to sy...@googlegroups.com
It should work now in the most recent build. Thanks for reporting the issue.

Duane Nykamp

unread,
Sep 6, 2014, 2:42:33 PM9/6/14
to sy...@googlegroups.com
Thanks for fixing this!

Duane Nykamp

unread,
Dec 29, 2014, 7:11:00 PM12/29/14
to sy...@googlegroups.com
More strange round behavior, this time with negative numbers.

In [1]: S(123.6).round(0)
Out[1]: 124.

In [2]: S(-123.6).round(0)
Out[2]: -123.

In [3]: S(-123.7).round(0)
Out[3]: -124.

The rounding up behavior seems to occur between 6 and 7.  This isn't a precision/binary representation issue as the break is occurring far away from the correct 5.  Standard python rounding get it right:

In [4]: round(123.6)
Out[4]: 124.0

In [5]: round(-123.6)
Out[5]: -124.0

Duane
Reply all
Reply to author
Forward
0 new messages