13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14 Expressionsthe result of the operation is the value of the second operand (even if that is also null). Otherwise, if thesecond operand is null, then the result of the operation is the value of the first operand. Otherwise, theresult of the operation is a new delegate instance that, when invoked, invokes the first operand and theninvokes the second operand. [Note: For examples of delegate combination, see §14.7.5 and §22.3. SinceSystem.Delegate is not a delegate type, operator + is not defined for it. end note]14.7.5 Subtraction operatorFor an operation of the form x – y, binary operator overload resolution (§14.2.4) is applied to select aspecific operator implementation. The operands are converted to the parameter types of the selectedoperator, and the type of the result is the return type of the operator.The predefined subtraction operators are listed below. The operators all subtract y from x.• Integer subtraction:int operator –(int x, int y);uint operator –(uint x, uint y);long operator –(long x, long y);ulong operator –(ulong x, ulong y);In a checked context, if the difference is outside the range of the result type, aSystem.OverflowException is thrown. In an unchecked context, overflows are not reported andany significant high-order bits outside the range of the result type are discarded.• Floating-point subtraction:float operator –(float x, float y);double operator –(double x, double y);The difference is computed according to the rules of IEC 60559 arithmetic. The following table lists theresults of all possible combinations of nonzero finite values, zeros, infinities, and NaNs. In the table, xand y are nonzero finite values, and z is the result of x – y. If x and y are equal, z is positive zero. Ifx – y is too large to represent in the destination type, z is an infinity with the same sign as x – y. Ifx – y is too small to represent in the destination type, z is a zero with the same sign as x – y.y +0 –0 +∞ –∞ NaNx z x x –∞ +∞ NaN+0 –y +0 +0 –∞ +∞ NaN–0 –y –0 +0 –∞ +∞ NaN+∞ +∞ +∞ +∞ NaN +∞ NaN–∞ –∞ –∞ –∞ –∞ NaN NaNNaN NaN NaN NaN NaN NaN NaN• Decimal subtraction:decimal operator –(decimal x, decimal y);If the resulting value is too large to represent in the decimal format, a System.OverflowExceptionis thrown. The scale of the result, before any rounding, is the larger of the scales of the two operands.Decimal subtraction is equivalent to using the subtraction operator of type System.Decimal.• Enumeration subtraction. Every enumeration type implicitly provides the following predefined operator,where E is the enum type, and U is the underlying type of E:U operator –(E x, E y);This operator is evaluated exactly as (U)((U)x – (U)y). In other words, the operator computes thedifference between the ordinal values of x and y, and the type of the result is the underlying type of theenumeration.161

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!