NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

7.7.5 Subtraction 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 subtraction operators are listed below. The operators all subtract y from x.

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, an OverflowException is thrown. In an unchecked context, overflows are not reported and any significant high-order bits of the result are discarded.

float operator –(float x, float y);
double operator –(double x, double y);

The difference 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 NaN’s. In the table, x and y are nonzero finite values, and z is the result of x – y. If x and y are equal, z is positive zero. If x – y is too large to represent in the destination type, z is an infinity with the same sign as x – y. If x – y is too small to represent in the destination type, z is a zero with the same sign as x – y.

  y +0 –0 +8 –8 NaN
x z x x –8 +8 NaN
+0 –y +0 +0 –8 +8 NaN
–0 –y –0 +0 –8 +8 NaN
+8 +8 +8 +8 NaN +8 NaN
–8 –8 –8 –8 –8 NaN NaN
NaN NaN NaN NaN NaN NaN NaN
decimal operator –(decimal x, decimal y);

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.

U operator –(E x, E y);

This operator is evaluated exactly as (U)((U)x – (U)y). In other words, the operator computes the difference between the ordinal values of x and y, and the type of the result is the underlying type of the enumeration.

E operator –(E x, U y);

This operator is evaluated exactly as (E)((U)x – y). In other words, the operator subtracts a value from the underlying type of the enumeration, yielding a value of the enumeration.

D operator –(D x, D y);