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 division operators are listed below. The operators all compute the quotient of 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);
If the value of the right operand is zero, a DivideByZeroException
is thrown.
The division rounds the result towards zero, and the absolute value of the result is the largest possible integer that is less than the absolute value of the quotient of the two operands. The result is zero or positive when the two operands have the same sign and zero or negative when the two operands have opposite signs.
If the left operand is the maximum negative int
or long
and the right operand is 1
, an overflow occurs. In a checked
context, this causes an OverflowException
to be thrown. In an unchecked
context, the overflow is not reported and the result is instead the value of the left operand.
float operator /(float x, float y); double operator /(double x, double y);
The quotient is computed according to the rules of IEEE 754 arithmetic. The following table lists the results of all possible combinations of nonzero finite values, zeros, infinities, and NaNs. In the table, x
and y
are positive finite values. z
is the result of x
/
y
. If the result is too large for the destination type, z
is infinity. If the result is too small for the destination type, z
is zero.
+y |
y |
+0 |
0 |
+8 |
8 |
NaN |
|
+x |
z |
z |
+8 |
8 |
+0 |
0 |
NaN |
x |
z |
z |
8 |
+8 |
0 |
+0 |
NaN |
+0 |
+0 |
0 |
NaN |
NaN |
+0 |
0 |
NaN |
0 |
0 |
+0 |
NaN |
NaN |
0 |
+0 |
NaN |
+8 |
+8 |
8 |
+8 |
8 |
NaN |
NaN |
NaN |
8 |
8 |
+8 |
8 |
+8 |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
decimal operator /(decimal x, decimal y);
If the value of the right operand is zero, a DivideByZeroException
is thrown. If the resulting value is too large to represent in the decimal
format, an OverflowException
is thrown. If the result value is too small to represent in the decimal
format, the result is zero.