Neither the reference docs or the decimal docs point out that the decimal type is not a binary128 or decimal128 value despite being listed among binary32 and binary64 values.
This is evident when we look at the representation of 1.0 in different 128-bit floating point formats (in little endian.)
Note that the last 2 bytes of decimal128 are different. Parsing the decimal128 value into System.Decimal either through GetBits or Memory casting will fail the IsValid() check (indicating it's not a Win32 DECIMAL.)
Since decimal128 and binary128 are standardized in the 2008 revision of the IEEE-754 format, this can lead to confusion when referring to decimal128 values (as System.Decimal is not an IEEE decimal float despite being a decimal floating point value.)
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
ID: b24345d9-7aec-14ad-8c3c-56410267849a
Version Independent ID: f83555d8-9dac-5019-3345-bb0f03e1311d
Issue description
Neither the reference docs or the decimal docs point out that the
decimal
type is not abinary128
ordecimal128
value despite being listed among binary32 and binary64 values.This is evident when we look at the representation of 1.0 in different 128-bit floating point formats (in little endian.)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F
0x1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x22
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Note that the last 2 bytes of decimal128 are different. Parsing the decimal128 value into System.Decimal either through GetBits or Memory casting will fail the IsValid() check (indicating it's not a Win32 DECIMAL.)
Since decimal128 and binary128 are standardized in the 2008 revision of the IEEE-754 format, this can lead to confusion when referring to decimal128 values (as System.Decimal is not an IEEE decimal float despite being a decimal floating point value.)
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.