Skip to content

Rename "modulo" to "remainder" #350

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
Apr 27, 2018

Conversation

cousteaulecommandant
Copy link
Contributor

When negative numbers are involved, "modulo" typically refers to an operation that has the same sign as the second operand, whereas "remainder" has the sign of the first (this distinction is clear e.g. in the Ada language, which has both mod and rem operators). Specifically, the standard refers to the result of % as "remainder", not "modulo".
In Python, for example, (-11) % 10 is 9, but in C and C++ it is -1). This can be a problem if % is being used to restrict an array index to a range (e.g. to implement a circular buffer), if said index can be negative.

I have replaced all occurrences of "modulo" with "remainder" in modulo.adoc, and provided two examples of what happens when you use % with negative operands. However I have left the file name as "modulo.adoc" (because honestly I have no idea what happens if you mess with the file names).

Replaced all occurrences of "modulo" with "remainder" in modulo.adoc
(since the behavior with negative numbers is more consistent with a remainder)
and added examples with negative numbers.
@SimonePDA
Copy link

I have to ask to the team if they agree on this change.

@Artoria2e5
Copy link
Contributor

An argument for this terminology can be that it is consistent with C/C++ standard (http://port70.net/~nsz/c) descriptions, but conversely it should be noted that C++11 calls it "modulus" too. Nevertheless "remainder" wins out at accuracy and familiarity.

@SimonePDA SimonePDA merged commit ec5fc48 into arduino:master Apr 27, 2018
@cousteaulecommandant
Copy link
Contributor Author

Should the file be renamed to remainder.adoc? Now it's everything fine except that the top of the documentation still says "Reference > Language > Structure > Arithmetic operators > Modulo" (I don't know if just changing the file name fixes this; I assumed the title_expanded: field would take care of this.)

@SimonePDA
Copy link

I took care of that change. Thank you for pointing that out.

@cousteaulecommandant
Copy link
Contributor Author

It would seem that remainder.adoc was successfully created, but the commit that removes modulo.adoc failed to build; as a result, there are now two entries for "% (remainder)" in https://www.arduino.cc/reference/en/

@SimonePDA
Copy link

Yes, I know. It is a bug about deletions. We will take care of it after this holidays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants