Reputation: 305
Sorry for a possible repeat question the %
symbol doesn't coincide with searchability.
What does %
mean? I can't seem to stick this one down.
Example:
rotation = value % MathHelper.TwoPi;
is a specific instance.
But I have found code that uses %
more often. Modulus I 'think' it is called, but I am not positive.
Upvotes: 3
Views: 3134
Reputation: 76414
Let's say that
x / y = z,
x, y, z being integers.
There is no guarantee that
z * y = x, because the "/" operator rounds down.
So we must add a remainder to our equation:
z * y = x + r.
z * y = x + r
z * (-y) = - (z * y) = -(x + r) = -x - r
This means that the result of the "%" operator can be negative, which means that the "%" or remainder operator differs from the modulo relation, because the result is not guaranteed to be canonical.
Upvotes: 3
Reputation: 70718
It is the modulus operator. It returns the remainder of an integer.
int remainder = 2 % 1; // (remainder variable is assigned to 0)
int remainder2 = 3 % 2; // (remainder variable is assigned to 1)
Upvotes: 3
Reputation: 125610
The % operator computes the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators.
Upvotes: 12
Reputation: 3654
Yes it' the modulus. http://en.wikipedia.org/wiki/Modulus_(algebraic_number_theory)
Upvotes: 3
Reputation: 56429
in C# it means modulus
, which is basically a remainder of
example:
int remainder = 10 % 3 //remainder is 1
Upvotes: 4
Reputation: 11740
It is the modulus operator. It computes the remainder after dividing its first operand by its second, e.g.
Upvotes: 4