Skip to content

DOC: Warn about the difference between np.remainder and math.remainder #9702

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 1 commit into from
Sep 18, 2017

Conversation

eric-wieser
Copy link
Member

Python 3.7 adds its own math.remainder with different semantics to ours.
We can't change the semantics now, but we can warn users that they are different.

* Python 3.7's `math.remainder` and C's ``remainder``, which
computes the IEEE remainder, which are the complement to
``round(x1 / x2)``.
* Matlab's ``rem``, which is the complement to ``int(x1 / x2)``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need the (TM) appendix? Just curious because the original version had one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was accidental - but doing a search seems to reveal that we don't use a TM sign anywhere else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other places, but all in the ufunc documentation. It looks like we don't need it for the function documentation, https://www.mathworks.com/brandguide/editorial/products.html, but we might want to put a copyright and trademark notice somewhere in the documentation, I don't know where.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the mathworks style guide wants it in caps and without the possessive suffix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've switched to all caps

Python 3.7 adds its own `math.remainder` with different semantics to ours.
We can't change the semantics now, but we can warn users that they are different.
@charris charris merged commit 97fc600 into numpy:master Sep 18, 2017
@charris
Copy link
Member

charris commented Sep 18, 2017

Thanks Eric.

@eric-wieser
Copy link
Member Author

Is there a reason that we didn't just name this function mod in the first place? To me it seems remainder was a really bad name to pick, since it's not the python name for this operation, and means something different in other languages too.

As an aside, should we add an ieee_remainder ufunc to mirror math.remainder?

@charris
Copy link
Member

charris commented Sep 18, 2017

The remainder name goes back to Numeric in the last century 8-) I'd be happy to add an ieee-remainder, we already have the other one, fmod. Looks like MSVC didn't get the remainder function before 2013 so we will need a fallback version.

@charris
Copy link
Member

charris commented Sep 18, 2017

The IEEE remainder might have an interesting interaction with the rounding mode, but should have good precision on both sides of zero for NumPy round to even, unlike floor remainder.

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.

3 participants