Skip to content

BUG: Fix divmod #7022

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

Merged
merged 2 commits into from
Jan 16, 2016
Merged

BUG: Fix divmod #7022

merged 2 commits into from
Jan 16, 2016

Conversation

charris
Copy link
Member

@charris charris commented Jan 15, 2016

Fix the remainder function so that it is consistent with floor_division.

Instead of using the C % operator, this PR computes remainder(a, b) as

b * (a/b - floor(a/b)),

which is consistent with implementing floor_division(a, b) as floor(a/b) and numerically better behaved than the implementation

a - b*floor(a/b).

Closes #6127.

This is apropos numpy#6127. The fix is to make the functions floor_division
and remainder consistent, i.e.,

    b * floor_division(a, b) + remainder(a, b) == a

Previous to this fix remainder was computed a the C level using the '%'
operator, and the result was not always consistent with the floor
function. The current approach is to compute the remainder using

    b * (a/b - floor(a/b))

which is both consistent with the Python '%' operator and numerically
consistent with floor_division implemented using the floor function.

Closes numpy#6127.
@charris charris added this to the 1.11.0 release milestone Jan 15, 2016
@charris charris changed the title Fix divmod BUG: Fix divmod Jan 16, 2016
charris added a commit that referenced this pull request Jan 16, 2016
@charris charris merged commit 115975e into numpy:master Jan 16, 2016
@charris charris deleted the fix-divmod branch January 16, 2016 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant