Skip to content

Document compound remainder #517

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
Feb 8, 2019
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
80 changes: 80 additions & 0 deletions Language/Structure/Compound Operators/compoundRemainder.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: "%="
title_expanded: compound remainder
categories: [ "Structure" ]
subCategories: [ "Compound Operators" ]
---





= %= Compound Remainder


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
This is a convenient shorthand to calculate the remainder when one integer is divided by another and assign it back to the variable the calculation was done on.
[%hardbreaks]


[float]
=== Syntax
[source,arduino]
----
x %= divisor; // equivalent to the expression x = x % divisor;
----

[float]
=== Parameters
`x`: variable. *Allowed data types:* int +
`divisor`: *non zero* variable or constant. *Allowed data types:* int

--
// OVERVIEW SECTION ENDS



// HOW TO USE SECTION STARTS
[#howtouse]
--

[float]
=== Example Code

[source,arduino]
----
int x = 7;
x %= 5; // x now contains 2
----
[%hardbreaks]

[float]
=== Notes and Warnings
1. The compound 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]

--
// HOW TO USE SECTION ENDS



//SEE ALSO SECTION BEGINS
[#see_also]
--

[float]
=== See also

[role="language"]
* #LANGUAGE# link:../../arithmetic-operators/remainder[Remainder]

--
// SEE ALSO SECTION ENDS