disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 13.2.1.xml
blob4bbed9c2f01cde66f40638b1d0f187e82fa8a2f9
1 <?xml version="1.0"?>
2 <clause number="13.2.1" title="Explicit numeric conversions">
3   <paragraph>The explicit numeric conversions are the conversions from a <non_terminal where="11.1">numeric-type</non_terminal> to another <non_terminal where="11.1">numeric-type</non_terminal> for which an implicit numeric conversion (<hyperlink>13.1.2</hyperlink>) does not already exist: <list><list_item> From <keyword>sbyte</keyword> to <keyword>byte</keyword>, <keyword>ushort</keyword>, <keyword>uint</keyword>, <keyword>ulong</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>byte</keyword> to <keyword>sbyte</keyword> and <keyword>char</keyword>. </list_item><list_item> From <keyword>short</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>ushort</keyword>, <keyword>uint</keyword>, <keyword>ulong</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>ushort</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>int</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>uint</keyword>, <keyword>ulong</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>uint</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>long</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>ulong</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>ulong</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, or <keyword>char</keyword>. </list_item><list_item> From <keyword>char</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, or <keyword>short</keyword>. </list_item><list_item> From <keyword>float</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, <keyword>ulong</keyword>, <keyword>char</keyword>, or <keyword>decimal</keyword>. </list_item><list_item> From <keyword>double</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, <keyword>ulong</keyword>, <keyword>char</keyword>, <keyword>float</keyword>, or <keyword>decimal</keyword>. </list_item><list_item> From <keyword>decimal</keyword> to <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, <keyword>ulong</keyword>, <keyword>char</keyword>, <keyword>float</keyword>, or <keyword>double</keyword>. </list_item></list></paragraph>
4   <paragraph>Because the explicit conversions include all implicit and explicit numeric conversions, it is always possible to convert from any <non_terminal where="11.1">numeric-type</non_terminal> to any other <non_terminal where="11.1">numeric-type</non_terminal> using a cast expression (<hyperlink>14.6.6</hyperlink>). </paragraph>
5   <paragraph>The explicit numeric conversions possibly lose information or possibly cause exceptions to be thrown. An explicit numeric conversion is processed as follows: <list><list_item> For a conversion from an integral type to another integral type, the processing depends on the overflow checking context (<hyperlink>14.5.12</hyperlink>) in which the conversion takes place: </list_item><list><list_item> In a checked context, the conversion succeeds if the value of the source operand is within the range of the destination type, but throws a System.OverflowException if the value of the source operand is outside the range of the destination type. </list_item><list_item> In an unchecked context, the conversion always succeeds, and proceeds as follows: </list_item><list><list_item> If the source type is larger than the destination type, then the source value is truncated by discarding its &quot;extra&quot; most significant bits. The result is then treated as a value of the destination type. </list_item><list_item> If the source type is smaller than the destination type, then the source value is either  sign-extended or zero-extended so that it is the same size as the destination type. Sign-extension is used if the source type is signed; zero-extension is used if the source type is unsigned. The result is then treated as a value of the destination type. </list_item><list_item> If the source type is the same size as the destination type, then the source value is treated as a value of the destination type. </list_item></list></list><list_item> For a conversion from <keyword>decimal</keyword> to an integral type, the source value is rounded towards zero to the nearest integral value, and this integral value becomes the result of the conversion. If the resulting integral value is outside the range of the destination type, a System.OverflowException is thrown. </list_item><list_item> For a conversion from <keyword>float</keyword> or <keyword>double</keyword> to an integral type, the processing depends on the  overflow-checking context (<hyperlink>14.5.12</hyperlink>) in which the conversion takes place: </list_item><list><list_item> In a checked context, the conversion proceeds as follows: </list_item><list><list_item> The value is rounded towards zero to the nearest integral value. If this integral value is within the range of the destination type, then this value is the result of the conversion. </list_item><list_item> Otherwise, a System.OverflowException is thrown. </list_item></list><list_item> In an unchecked context, the conversion always succeeds, and proceeds as follows: </list_item><list><list_item> The value is rounded towards zero to the nearest integral value. If this integral value is within the range of the destination type, then this value is the result of the conversion. </list_item><list_item> Otherwise, the result of the conversion is an unspecified value of the destination type. </list_item></list></list><list_item> For a conversion from <keyword>double</keyword> to <keyword>float</keyword>, the <keyword>double</keyword> value is rounded to the nearest <keyword>float</keyword> value. If the <keyword>double</keyword> value is too small to represent as a <keyword>float</keyword>, the result becomes positive zero or negative zero. If the <keyword>double</keyword> value is too large to represent as a <keyword>float</keyword>, the result becomes positive infinity or negative infinity. If the <keyword>double</keyword> value is NaN, the result is also NaN. </list_item><list_item> For a conversion from <keyword>float</keyword> or <keyword>double</keyword> to <keyword>decimal</keyword>, the source value is converted to <keyword>decimal</keyword> representation and rounded to the nearest number after the 28th <keyword>decimal</keyword> place if required (<hyperlink>11.1.6</hyperlink>). If the source value is too small to represent as a <keyword>decimal</keyword>, the result becomes zero. If the source value is NaN, infinity, or too large to represent as a <keyword>decimal</keyword>, a System.OverflowException is thrown. </list_item><list_item> For a conversion from <keyword>decimal</keyword> to <keyword>float</keyword> or <keyword>double</keyword>, the <keyword>decimal</keyword> value is rounded to the nearest <keyword>double</keyword> or <keyword>float</keyword> value. While this conversion may lose precision, it never causes an exception to be thrown. </list_item></list></paragraph>
6 </clause>