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.

<strong>C#</strong> LANGUAGE SPECIFICATION11.1.6 The decimal typeThe decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal typecan represent values ranging from 1.0 × 10 −28 to approximately 7.9 × 10 28 with 28–29 significant digits.The finite set of values of type decimal are of the form (–1) s × c × 10 -e , where the sign s is 0 or 1, thecoefficient c is given by 0 ≤ c < 2 96 , and the scale e is such that 0 ≤ e ≤ 28. The decimal type does notsupport signed zeros, infinities, or NaN's.A decimal is represented as a 96-bit integer scaled by a power of ten. For decimals with an absolute valueless than 1.0m, the value is exact to the 28 th decimal place, but no further. For decimals with an absolutevalue greater than or equal to 1.0m, the value is exact to 28 or 29 digits. Contrary to the float and doubledata types, decimal fractional numbers such as 0.1 can be represented exactly in the decimalrepresentation. In the float and double representations, such numbers are often infinite fractions, makingthose representations more prone to round-off errors.If one of the operands of a binary operator is of type decimal, then the other operand must be of an integraltype or of type decimal. If an integral type operand is present, it is converted to decimal before theoperation is performed.The result of an operation on values of type decimal is that which would result from calculating an exactresult (preserving scale, as defined for each operator) and then rounding to fit the representation. Results arerounded to the nearest representable value, and, when a result is equally close to two representable values, tothe value that has an even number in the least significant digit position (this is known as “banker’srounding”). That is, results are exact to 28 or 29 digits, but to no more than 28 decimal places. A zero resultalways has a sign of 0 and a scale of 0.If a decimal arithmetic operation produces a value that is too small for the decimal format after rounding, theresult of the operation becomes zero. If a decimal arithmetic operation produces a result that is too largefor the decimal format, a System.OverflowException is thrown.The decimal type has greater precision but smaller range than the floating-point types. Thus, conversionsfrom the floating-point types to decimal might produce overflow exceptions, and conversions fromdecimal to the floating-point types might cause loss of precision. For these reasons, no implicit conversionsexist between the floating-point types and decimal, and without explicit casts, it is not possible to mixfloating-point and decimal operands in the same expression.11.1.7 The bool typeThe bool type represents boolean logical quantities. The possible values of type bool are true and false.No standard conversions exist between bool and other types. In particular, the bool type is distinct andseparate from the integral types, and a bool value cannot be used in place of an integral value, and viceversa.[Note: In the C and C++ languages, a zero integral or floating-point value, or a null pointer can be convertedto the boolean value false, and a non-zero integral or floating-point value, or a non-null pointer can beconverted to the boolean value true. In <strong>C#</strong>, such conversions are accomplished by explicitly comparing anintegral or floating-point value to zero, or by explicitly comparing an object reference to null. end note]11.1.8 Enumeration typesAn enumeration type is a distinct type with named constants. Every enumeration type has an underlyingtype, which must be byte, sbyte, short, ushort, int, uint, long or ulong. Enumeration types aredefined through enumeration declarations (§21.1).11.2 Reference typesA reference type is a class type, an interface type, an array type, or a delegate type.94

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

Saved successfully!

Ooh no, something went wrong!