7.7.3 Remainder operator
For an operation of the form
y, binary operator overload resolution (Section 7.2.4) is applied to select a specific operator implementation. The operands are converted to the parameter types of the selected operator, and the type of the result is the return type of the operator.
The predefined remainder operators are listed below. The operators all compute the remainder of the division between
- Integer remainder:
int operator %(int x, int y); uint operator %(uint x, uint y); long operator %(long x, long y); ulong operator %(ulong x, ulong y);
The result of
y is the value produced by
y is zero, a
System.DivideByZeroException is thrown. The remainder operator never causes an overflow.
- Floating-point remainder:
float operator %(float x, float y); double operator %(double x, double y);
The following table lists the results of all possible combinations of nonzero finite values, zeros, infinities, and NaN's. In the table,
y are positive finite values.
z is the result of
y and is computed as
n is the largest possible integer that is less than or equal to
y. This method of computing the remainder is analogous to that used for integer operands, but differs from the IEEE 754 definition (in which
n is the integer closest to
- Decimal remainder:
decimal operator %(decimal x, decimal y);
If the value of the right operand is zero, a
System.DivideByZeroException is thrown. The scale of the result, before any rounding, is the larger of the scales of the two operands, and the sign of the result, if non-zero, is the same as that of
Decimal remainder is equivalent to using the remainder operator of type