Decimal64 floating-point format: Difference between revisions

Content deleted Content added
Undid revision 328793080 by 88.205.141.131 (talk) The significand defined as a positive INTEGER, so the bias is -398.
Tag: Non-autoconfirmed user rapidly reverting edits
Adapted (better) Decimal32 article.
Line 1:
{{floating-point}}
In [[computing]], '''decimal64''' is a decimal [[floating-point]] [[computer numbering format]] that occupies 8 bytes (64 bits) in computer memory.
In [[computing]], '''decimal64''' is a decimal [[floating-point]] [[computer numbering format]] that occupies 8 bytes (64 bits) in computer memory.
It is intended for applications where it is necessary to emulate decimal rounding exactly, such as financial and tax computations.
 
Decimal64 supports 16 [[decimal digit]]s of [[significand]] and an [[exponent]] range of −383 to +384, i.e. ±0.000000000000000×10<sup>−383</sup> to ±9.999999999999999×10<sup>384</sup>. (Equivalently, ±0,000,000,000,000,000×10<sup>−398</sup> to ±9,999,999,999,999,999×10<sup>369</sup>.) Because the significand is not normalized, most values with less than 16 [[significant digits]] have multiple possible representations; 1×10<sup>2</sup>=0.1×10<sup>3</sup>=0.01×10<sup>4</sup>, etc. Zero has 768 possible representations (1536 if you include both [[signed zero]]s).
Decimal64 floating point is a relatively new decimal floating-point format, formally introduced in the 2008 version of [[IEEE 754]].
 
Decimal64 floating point is a relatively new decimal floating-point format, formally introduced in the 2008 version of [[IEEE 754]].
{{floating-point}}
 
== Representation of decimal64 values ==
 
IEEE 754 allows two alternative representation methods for ''decimal64'' values.
The standard does not specify how to signify which representation is used,
for instance in a situation where decimal64 values are communicated between systems.
 
In one representation method, based on [[binary integer decimal]],
the [[significand]] is represented as binary coded positive integer.
 
The other, alternative, representation method is based on
Line 18 ⟶ 20:
significand (except the most significant digit).
 
Both alternatives provide exactly the same range of representable numbers: 16 digits of significand and 3×2<sup>8</sup> = 768 possible exponent values.
 
In both cases, the most significant 4 bits of the significand (which actually only have 10 possible values) are combined with the most significant 2 bits of the exponent (3 possible values) to use 30 of the 32 possible values of a 5-bit field. The remaining combinations encode [[infinity|infinities]] and [[NaN]]s.
=== Binary integer significand field ===
 
If the leading 4 bits of the significand is between 0 and 7, the number begins as follows
The position of the exponent and significand parts, as well as whether there
is an implicit lead "100" bit triplet (see below) depends on the value of
the bits following the sign bit (''s'' below).
 
s 00 xxxx Exponent begins with 00, significand with 0mmm
If the 2 bits after the sign bit are "00", "01", or "10", then the
s 01 xxxx Exponent begins with 01, significand with 0mmm
exponent field consists of the 10 bits following the sign bit, and the
s 10 xxxx Exponent begins with 10, significand with 0mmm
sigificand are the remaining 53 bits.
 
If the leading 4 bits of the significand are binary 1000 or 1001 (decimal 8 or 9), the number begins as follows:
s 00eeeeeeee TTTtttttttttttttttttttt tttttttttttttttttttttttttttttt
s 01eeeeeeee TTTtttttttttttttttttttt tttttttttttttttttttttttttttttt
s 10eeeeeeee TTTtttttttttttttttttttt tttttttttttttttttttttttttttttt
 
s 1100 xx Exponent begins with 00, significand with 100m
This includes representation of [[subnormal numbers]].
s 1101 xx Exponent begins with 01, significand with 100m
s 1110 xx Exponent begins with 10, significand with 100m
 
The following bits (xxx in the above) encode the additional exponent bits and the remainder of the most significant digit, but the details vary depending on the encoding alternative used. There is no particular reason for this difference, other than historical reasons in the eight-year long development of IEEE 754-2008.
If the 4 bits after the sign bit are "1100", "1101", or "1110", then the
exponent field consists of the 10 bits following the sign bit and the "11" bits
thereafter, and the represented sigificand are in the remaining 51 bits. In this
case there is an implicit (that is, not stored) "100" 3-bit sequence in the true significand.
 
The final combinations are used for infinities and NaNs, and are the same for both alternative encodings:
s 11 00eeeeeeee (100)Ttttttttttttttttttttt tttttttttttttttttttttttttttttt
s 11 01eeeeeeee (100)Ttttttttttttttttttttt tttttttttttttttttttttttttttttt
s 11 10eeeeeeee (100)Ttttttttttttttttttttt tttttttttttttttttttttttttttttt
 
s 11110 x ±Infinity (see [[Extended real number line]])
Note that the "11" 2-bit sequence after sign bit indicates that there is an ''implicit'' "100" 3-bit
s 111110 quiet NaN (sign bit ignored)
lead sequence in the true significand. Compare having an implicit 1 in the significand of normal
s 111111 signaling NaN (sign bit ignored)
values for the binary formats. Note also that the "00", "01", or "10" bits are part of the exponent field.
Note also that zero (both positive and [[-0 (number)|negative]]) have very many representations.
Also other numbers, subnormal as well as normal, can have multiple representations. Trailing decimal
zeroes can be shifted in or out, if possible without changing the value, while adjusting the exponent.
This shifting is not a bitwise shift, but division/multiplication by ten.
 
In the latter cases, all other bits of the encoding are ignored. Thus, it is possible to initialize an array to NaNs by filling it with a single byte value.
The true significand is limited to
 
=== Binary integer significand field ===
10<sup>16</sup>-1 = 9 999 999 999 999 999 = 100 011 100 001 101 111 001 001 101 111 110 000 001 111 111 111 111 111<sub>2</sub>
This format uses a binary significand from 0 to 10<sup>16</sup>−1 = 9,999,999,999,999,999 = 2386F26FC0FFFF<sub>16</sub> =
1000&thinsp;1110000110&thinsp;1111001001&thinsp;1011111100&thinsp;0000111111&thinsp;1111111111<sub>2</sub>.
The encoding can represent binary significands up to 10×2<sup>50</sup>−1 = 11,258,999,068,426,239 = 27FFFFFFFFFFFF<sub>16</sub>, but values larger than 10<sup>7</sup>−1 are illegal (and the standard requires implementations to treat them as 0, if encountered on input).
 
As described above, the encoding varies depending on whether the most significant 4 bits of the significand are in the range 0 to 7 (0000<sub>2</sub> to 0111<sub>2</sub>), or higher (1000<sub>2</sub> or 1001<sub>2</sub>).
If the represented significand value, including the "100" implicit lead bits when the sign bit
is followed by "11", is greater than that, then the significand is in error, but is to be
interpreted as if it was 0 (including the implicit lead bits).
 
If the 2 bits after the sign bit are "00", "01", or "10", then the
In the above cases, the value represented is
exponent field consists of the 10 bits following the sign bit, and the
significand is the remaining 53 bits, with an implicit leading 0 bit:
 
s 00eeeeeeee (0)TTTtttttttttttttttttt tttttttttttttttttttttttttttttttt
<math>(-1)^\text{signbit}\times 10^{\text{exponentbits}_2-398}\times \text{truesignificand}_2</math>
s 01eeeeeeee (0)TTTtttttttttttttttttt tttttttttttttttttttttttttttttttt
s 10eeeeeeee (0)TTTtttttttttttttttttt tttttttttttttttttttttttttttttttt
 
This includes [[subnormal numbers]] where the leading significand digit is 0.
If the five bits after the sign bit are "11110" then the value is an [[infinity]],
(compare the [[extended real number line]]),
with the sign indicated by the sign bit. The remaining 58 bits are ignored.
 
If the 4 bits after the sign bit are "1100", "1101", or "1110", then the 10-bit exponent field is shifted 2 bits to the right (after both the sign bit and the "11" bits thereafter), and the represented significand is in the remaining 51 bits. In this case there is an implicit (that is, not stored) leading 3-bit sequence "100" in the true significand.
s 11110 x...x an infinity
 
s 11 00eeeeeeee (100)Ttttttttttttttttttt tttttttttttttttttttttttttttttttt
If the six bits after the sign bit are 111110, the value is a quiet [[NaN]].
s 11 01eeeeeeee (100)Ttttttttttttttttttt tttttttttttttttttttttttttttttttt
The sign bit and the remaining bits after this special sequence have no meaningful interpretation.
s 11 10eeeeeeee (100)Ttttttttttttttttttt tttttttttttttttttttttttttttttttt
 
The "11" 2-bit sequence after the sign bit indicates that there is an ''implicit'' "100" 3-bit
s 111110 x...x a quiet NaN
prefix to the significand. Compare having an implicit 1 in the significand of normal
values for the binary formats. Note also that the "00", "01", or "10" bits are part of the exponent field.
 
Note that the leading bits of the significand field do ''not'' encode the most significant decimal digit; they are simply part of a larger pure-binary number. For example, a significand of 8,000,000,000,000,000 is encoded as binary 111&thinsp;0001101011&thinsp;1111010100&thinsp;1001100011&thinsp;0100000000&thinsp;0000000000, with the leading 4 bits encoding 7; the first significand which requires a 54th bit is 2<sup>53</sup> = 9,007,199,254,740,992.
If the six bits after the sign bit are 111111, the value is a signalling NaN.
The sign bit and the remaining bits after this special sequence have no meaningful interpretation.
 
In the above cases, the value represented is
 
: (−1)<sup>sign</sub> × 10<sup>exponent−398</sup> × significand <!-- Remember, significand is defined as an integer: 0 <= significand < 10^16 -->
 
If the four bits after the sign bit are "1111" then the value is an infinity or a NaN, as described above:
 
s 11110 xx...x ±infinity
s 111110 x...x a quiet NaN
s 111111 x...x a signalling NaN
 
=== Densely packed decimal significand field ===
In this version, the significand is stored as a series of decimal digits. The leading digit is between
0 and 9 (3 or 4 binary bits), and the rest of the significand uses the [[densely packed decimal]] encoding.
 
Unlike the binary integer significand version, where the exponent changed position and came before the significand, this encoding combines the leading 2 bits of the exponent and the leading digit (3 or 4 bits)
For the alternative using DPD encoding for most of the significand, the position
of the exponent part and significand partsinto dothe notfive move,bits butthat follow the implicitsign bit.
lead bits of the exponent and the lead digit of the significand depend on
the five bits that follow the sign bit.
 
TheThis last 50eight bits after that are the significandexponent continuation field, consistingproviding the less-significant bits of 5the "declets"exponent.
A ''declet'' is 10 bits in DPD encoding, coding three decimal digits.
 
The eightlast 50 bits beforeare the significand continuation field, isconsisting theof exponent5 field10-bit "declets".
Each declet encodes three decimal digits using the DPD encoding.
 
If the first two bits after the sign bit are "00", "01", or "10", then thethose are
the leading bits of the exponent, and the three bits after that are interpreted as
exponent field has those two bits as (semi)implicit lead bits.
the leading decimal digit (0 to 7):
The three bits after the "00", "01", or "10" bits are interpreted as
the lead decimal digit (0 to 7).
 
s 00 mmmTTT (00)eeeeeeee (mmmTTT)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
s 01 mmmTTT (01)eeeeeeee (mmmTTT)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
s 10 mmmTTT (10)eeeeeeee (mmmTTT)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
 
If the 4 bits after the sign bit are "1100", "1101", or "1110", then the
second two bits are the leading bits of the exponent, and the last bit is
exponent field has last two bits of those four bits as (semi)implicit lead bits.
prefixed with "100" to form the leading decimal digit (8 or 9):
The bit just before the exponent field is prefixed with "100" and is
interpreted as the lead digit for the significand (8 or 9).
 
s 1100 mT (00)eeeeeeee (100m100T)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
s 1101 mT (01)eeeeeeee (100m100T)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
s 1110 mT (10)eeeeeeee (100m100T)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
 
The remaining two combinations (11110 and 11111) of the 5-bit field
The declets of the significand field are interpreted according to the
are used to represent ±infinity and NaNs, respectively.
DPD encoding into 3 decimal digits per declet, following the lead decimal digit.
24 of the declet bit combinations are ill-formed, in which case the
significand is in error, but the declet is still interpreted as
coding a three-digit decimal sequence.
 
The DPD/3BCD transcoding for the declets is given by the following table.
Line 121:
{{Densely packed decimal}}
 
DecimalThe values8 ofdecimal thevalues form,whose asdigits aare regularall expression,8s (8|9)(8|9)(8|9),or eight values,9s have four codings each.
The bits marked x in the table above are ignored on input, but will always be 0 in computed results.
This is a total of 32 DPD encodings for eight values, and thus an excess of 24 DPD encodings.
(The 8×3 = 24 non-standard encodings fill in the gap between 10<sup>3</sup>=1000 and 2<sup>10</sup>=1024.)
The x marked bit values, in the table above, for the b9 and b8 bits, are ignored on input,
but should be 0, and will be 0 in computed results.
 
In the above cases, with the ''truesignificand'' as the sequence of decimal digits decoded, the value represented is
 
<math>(-1)^\text{signbit}\times 10^{\text{exponentbits}_2-398}\times \text{truesignificand}_{10}</math>
 
In the above cases, with the ''true significand'' as the sequence of decimal digits decoded, the value represented is
The exponent range and digit precision are the same for both alternative encodings. There is no particular reason why the exponent part in this encoding alternative has the bits arranged in a different way than in the other alternative described above (and with the represented bit(s) of the lead decimal digit of the significand just before the declets), other than historical reasons in the eight-year long development of IEEE 754-2008.
 
:<math>(-1)^\text{signbit}\times 10^{\text{exponentbits}_2-398_{10}}\times \text{truesignificand}_{10}</math>
The encoding for the infinities and NaNs are the same for both alternative encodings.
 
== See also ==