Skip to content

Commit ec5fc48

Browse files
author
SimonePDA
authored
Merge pull request #350 from cousteaulecommandant/patch-1
Rename "modulo" to "remainder". Ok, we ageed on this change.
2 parents 623e3d8 + 2ae05fb commit ec5fc48

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Language/Structure/Arithmetic Operators/modulo.adoc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "%"
3-
title_expanded: "modulo"
3+
title_expanded: "remainder"
44
categories: [ "Structure" ]
55
subCategories: [ "Arithmetic Operators" ]
66
---
@@ -9,7 +9,7 @@ subCategories: [ "Arithmetic Operators" ]
99

1010

1111

12-
= % Modulo
12+
= % Remainder
1313

1414

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

1919
[float]
2020
=== Description
21-
*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.
21+
*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.
2222
[%hardbreaks]
2323

2424

@@ -55,6 +55,8 @@ x = 7 % 5; // x now contains 2
5555
x = 9 % 5; // x now contains 4
5656
x = 5 % 5; // x now contains 0
5757
x = 4 % 5; // x now contains 4
58+
x = -4 % 5; // x now contains -4
59+
x = 4 % -5; // x now contains 4
5860
----
5961

6062
[source,arduino]
@@ -69,14 +71,17 @@ void setup() {}
6971
void loop()
7072
{
7173
values[i] = analogRead(0);
72-
i = (i + 1) % 10; // modulo operator rolls over variable
74+
i = (i + 1) % 10; // remainder operator rolls over variable
7375
}
7476
----
7577
[%hardbreaks]
7678

7779
[float]
7880
=== Notes and Warnings
79-
The modulo operator does not work on floats.
81+
1. The remainder operator does not work on floats.
82+
83+
2. If the *first* operand is negative, the result is negative (or zero).
84+
Therefore, the result of `x % 10` will not always be between 0 and 9 if `x` can be negative.
8085
[%hardbreaks]
8186

8287
--

0 commit comments

Comments
 (0)