|
JM
Task group work on edition 3 of the ECMA CLI specification consisted of discussion around Decimal. Ultimately, the Decimal specification was relaxed in order to accommodate a new format coming out of the IEEE 754r specification. While the original format is still supported, a string-based was added to DecimalConstantAttribute to accommodate this new format.
JM
DecimalConstantAttribute is emitted by compilers (e.g., C#) when a field is declared as a const decimal.
RJ
The metadata does not directly support the representation of constants of type System.Decimal. As a result, in the code generated by the C# (and VB) compiler, they are stored as an attribute using the type DecimalConstantAttribute. Consider the following C# code:
public class Test
{
private const decimal d = 12.3456m;
}
The relevant MSIL generated is
.field private static initonly valuetype [mscorlib]System.Decimal d
.custom instance void
[mscorlib]
System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(
uint8, uint8, uint32, uint32, uint32) = ( … hex bytes … )
This type is not intended to be used directly by programmers, but rather by compiler writers, based on the programmer's use of some language syntax (such as the keywords const decimal in C#).
Note that it is expected that a future implementation of the CLI will support an alternate representation of the decimal type, which has a much larger range, and a scale that exceeds eight bits. As such, new constructors and methods are likely to be added to this type, as well as to System.Decimal.
DT
DecimalConstantAttribute provides compilers a place to store decimal constants, since metadata itself can't represent values that big in situ. This attribute is only generated by compilers to indicate the constant value to reflectors and other compilers. The attribute is not used by the runtime or executing code.
DT
This attribute has been a hot topic in ECMA discussions. A new IEEE 128-bit decimal representation offers more range/precision (in the same number of bits!) than the current CLR implementation. If CLR were to support this new IEEE decimal in the future, this attribute will present a problem because the IEEE decimal's scale is wider than the byte type of the constructor's scale parameter. It is likely that the parameter types of the constructor will be widened and/or additional constructors added in a future release to make an IEEE decimal implementation an option for a future CLR release.
DT
Some have suggested adding constructors with fewer parameters to make it easier for people to construct DecimalConstantAttributes. The only problem with that is that people don't construct DecimalConstantAttributes—compilers do, so convenience isn't really necessary. |