New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SymPy's Number.__divmod__ doesn't agree with the builtin divmod #15561

Closed
asmeurer opened this Issue Nov 28, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@asmeurer
Copy link
Member

asmeurer commented Nov 28, 2018

>>> divmod(4, -2.1)
(-2.0, -0.20000000000000018)
>>> divmod(S(4), S(-2.1))
(-1, 1.9)

Both are mathematically correct according to the invariant in the divmod docstring, div*y + mod == x, but we should be consistent with Python. In general in Python, the sign of mod should be the same as the sign of the second argument.

>>> -1*-2.1 + 1.9
4.0
>>> -2.0*-2.1 + -0.2
4.0

Our Mod is already correct, so it's just Number.__divmod__ that needs to be corrected

>>> Mod(4, -2.1)
-0.200000000000000

@asmeurer asmeurer added the core label Nov 28, 2018

asmeurer added a commit to asmeurer/sympy that referenced this issue Nov 28, 2018

Implement divmod on Expr
Closes sympy#7889.

Note there is a separate issue with a discrepancy between the builtin divmod
and divmod on SymPy number types that is not fixed here (sympy#15561).

skirpichev added a commit to skirpichev/diofant that referenced this issue Dec 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment