X hits on this document

760 views

0 shares

0 downloads

0 comments

156 / 396

Chapter ‎18   Unsafe code

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 x % y is the value produced by x (x / y) * y. If 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, 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. 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 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 x.

Decimal remainder is equivalent to using the remainder operator of type System.Decimal.

7.7.4 Addition operator

For an operation of the form x + y, binary operator overload resolution (§‎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 addition operators are listed below. For numeric and enumeration types, the predefined addition operators compute the sum of the two operands. When one or both operands are of type string, the predefined addition operators concatenate the string representation of the operands.

Integer addition:

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.143

Document info
Document views760
Page views760
Page last viewedSat Dec 03 00:21:46 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments