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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Language/Structure/Arithmetic Operators/modulo.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "%"
title_expanded: "modulo"
title_expanded: "remainder"
categories: [ "Structure" ]
subCategories: [ "Arithmetic Operators" ]
---
Expand All @@ -9,7 +9,7 @@ subCategories: [ "Arithmetic Operators" ]



= % Modulo
= % Remainder


// OVERVIEW SECTION STARTS
Expand All @@ -18,7 +18,7 @@ subCategories: [ "Arithmetic Operators" ]

[float]
=== Description
*Modulo* operation calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array). The `%` (percent) symbol is used to carry out modulo operation.
*Remainder* operation calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array). The `%` (percent) symbol is used to carry out remainder operation.
[%hardbreaks]


Expand Down Expand Up @@ -55,6 +55,8 @@ x = 7 % 5; // x now contains 2
x = 9 % 5; // x now contains 4
x = 5 % 5; // x now contains 0
x = 4 % 5; // x now contains 4
x = -4 % 5; // x now contains -4
x = 4 % -5; // x now contains 4
----

[source,arduino]
Expand All @@ -69,14 +71,17 @@ void setup() {}
void loop()
{
values[i] = analogRead(0);
i = (i + 1) % 10; // modulo operator rolls over variable
i = (i + 1) % 10; // remainder operator rolls over variable
}
----
[%hardbreaks]

[float]
=== Notes and Warnings
The modulo operator does not work on floats.
1. The remainder operator does not work on floats.

2. If the *first* operand is negative, the result is negative (or zero).
Therefore, the result of `x % 10` will not always be between 0 and 9 if `x` can be negative.
[%hardbreaks]

--
Expand Down