14.7.1 Multiplication operator

王朝other·作者佚名  2006-03-10
窄屏简体版  字體: |||超大  

For an operation of the form x * y, binary operator overload resolution (?4.

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 multiplication operators are listed below. The operators all

compute the product of x and y.

?Integer multiplication:

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 product is outside the range of the result

type, a

System.OverflowException is thrown. In an unchecked context, overflows are

not reported and

any significant high-order bits outside the range of the result type are

discarded.

?Floating-point multiplication:

float operator *(float x, float y);

double operator *(double x, double y);

Chapter 14 Expressions

157

The product is computed according to the rules of IEC 60559 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 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 +0 -0 +8 -8 NaN

-x -z +z -0 +0 -8 +8 NaN

+0 +0 -0 +0 -0 NaN NaN NaN

-0 -0 +0 -0 +0 NaN NaN NaN

+8 +8 -8 NaN NaN +8 -8 NaN

-8 -8 +8 NaN NaN -8 +8 NaN

NaN NaN NaN NaN NaN NaN NaN NaN

?Decimal multiplication:

decimal operator *(decimal x, decimal y);

If the resulting value is too large to represent in the decimal format, a

System.OverflowException

is thrown. If the result value is too small to represent in the decimal

format, the result is zero. The scale

of the result, before any rounding, is the sum of the scales of the two

operands.

Decimal multiplication is equivalent to using the multiplication operator

of type System.Decimal.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航