
14 Expressions
14.7 Arithmetic operators
14.7.3 Remainder operator
Paragraph 11 For an operation of the form x % y, binary operator overload resolution (§14.2.4) is applied to select a specific operator implementation. 2 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.
Paragraph 21 The predefined remainder operators are listed below. 2 The operators all compute the remainder of the division between x and y. int operator %(int x, int y); uint operator %(uint x, uint y); long operator %(long x, long y); ulong operator %(ulong x, ulong y);4 The result of x % y is the value produced by x -(x / y) * y. 5 If y is zero, a System.DivideByZeroException is thrown. 6 The remainder operator never causes an overflow.
float operator %(float x, float y); double operator %(double x, double y);8 The following table lists the results of all possible combinations of nonzero finite values, zeros, infinities, and NaN's. 9 In the table, x and y are positive finite values. z is the result of x % y and is computed as x -n * y, where n is the largest possible integer that is less than or equal to x / y. 10 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 x / y).
| % | +y | -y | +0 | -0 | +∞ | -∞ | NaN |
|---|---|---|---|---|---|---|---|
| +x | +z | +z | NaN | NaN | x | x | NaN |
| -x | -z | -z | NaN | NaN | -x | -x | NaN |
| +0 | +0 | +0 | NaN | NaN | +0 | +0 | NaN |
| -0 | -0 | -0 | NaN | NaN | -0 | -0 | NaN |
| +∞ | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| -∞ | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
decimal operator %(decimal x, decimal y);12 If the value of the right operand is zero, a System.DivideByZeroException is thrown. 13 If the resulting value is too large to represent in the decimal format, a System.OverflowException is thrown. 14 If the result value is too small to represent in the decimal format, the result is zero. 15 The scale of the result, before any rounding, is the same as the scale of y, and the sign of the result, if non-zero, is the same as that of x. 16 Decimal remainder is equivalent to using the remainder operator of type System.Decimal.
| |
| Jagger Software Ltd | |
| Company # 4070126 | |
| VAT # 762 5213 42 |