Decimal64 floating-point format: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Removed URL that duplicated identifier. Removed access-date with no URL. | Use this bot. Report bugs. | Suggested by Headbomb | Linked from Wikipedia:WikiProject_Academic_Journals/Journals_cited_by_Wikipedia/Sandbox | #UCB_webform_linked 629/1032
 
(131 intermediate revisions by 60 users not shown)
Line 1:
{{Short description|64-bit computer number format}}
In [[computing]], '''decimal64''' is a decimal [[floating-point]] [[computer numbering format]] that occupies 8 bytes (64 bits) in computer memory.
{{lowercase title}}
 
{{Use dmy dates|date=July 2020|cs1-dates=y}}
Decimal64 floating point is a relatively new decimal floating-point format, formally introduced in the 2008 version of [[IEEE 754]].
 
{{floating-point}}
In [[computing]], '''decimal64''' is a [[decimal floating point|decimal floating-point]] [[computer number format]] that occupies 8 bytes (64 bits) in computer memory.
 
Decimal64 is a decimal floating-point format, formally introduced in the [[IEEE 754-2008 revision|2008 revision]]<ref name="IEEE-754_2008">{{cite book |title=IEEE Standard for Floating-Point Arithmetic |author=IEEE Computer Society |date=2008-08-29 |publisher=[[IEEE]] |id=IEEE Std 754-2008 |doi=10.1109/IEEESTD.2008.4610935 |ref=CITEREFIEEE_7542008 |isbn=978-0-7381-5753-5 }}</ref> of the [[IEEE 754]] standard, also known as ISO/IEC/IEEE 60559:2011.<ref name="ISO-60559_2011">{{Cite book |last=ISO/IEC JTC 1/SC 25|title=ISO/IEC/IEEE 60559:2011 — Information technology — Microprocessor Systems — Floating-Point arithmetic |url=https://www.iso.org/standard/57469.html |publisher=ISO |pages=1–58 |date=June 2011}}</ref>
== Representation of decimal64 values ==
 
== Format ==
IEEE 754 allows two alternative representation methods for ''decimal64'' values.
Decimal64 supports 'normal' values that can have 16 digit precision from {{gaps|±1.000|000|000|000|000|e=-383}} to {{gaps|±9.999|999|999|999|999|e=384}}, plus 'denormal' values with ramp-down relative precision down to ±1.×10<sup>−398</sup>, [[signed zero]]s, signed infinities and [[NaN]] (Not a Number). This format supports two different encodings.
The standard does not specify how to signify which representation is used,
for instance in a situation where decimal64 values are communicated between systems.
 
The binary format of the same size supports a range from denormal-min {{gaps|±5|||||e=-324|}}, over normal-min with full 53-bit precision {{gaps|±2.225|073|858|507|201|e=-308|4}} to max {{gaps|±1.797|693|134|862|315|e=+308|7}}.
In one representation method, based on [[binary integer decimal]],
the [[significand]] is represented as binary coded positive integer.
 
Because the significand for the [[IEEE 754]] decimal formats is not normalized, most values with less than 16 [[significant digits]] have multiple possible representations; 1000000 × 10<sup>−2</sup>=100000 × 10<sup>−1</sup>=10000 × 10<sup>0</sup>=1000 × 10<sup>1</sup> all have the value 10000. These sets of representations for a same value are called ''[[Cohort (floating point)|cohorts]]'', the different members can be used to denote how many digits of the value are known precisely. Each signed zero has 768 possible representations (1536 for all zeros, in two different cohorts).
The other, alternative, representation method is based on
[[densely packed decimal]] for most of the
significand (except the most significant digit).
 
== Encoding of decimal64 values ==
 
{| class="wikitable"
=== Binary integer significand field ===
|-
! Sign !! Combination !! Significand continuation
|-
! 1 bit !! 13 bits !! 50 bits
|-
| {{mono|s}} || {{mono|mmmmmmmmmmmmm}} || {{mono|cccccccccccccccccccccccccccccccccccccccccccccccccc}}
|}
 
IEEE 754 allows two alternative encodings 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:
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).
 
* In the [[#Binary integer significand field|binary encoding]], the 16-digit significand is represented as a binary coded positive integer, based on [[binary integer decimal]] (BID).
If the 2 bits after the sign bit are "00", "01", or "10", then the
* In the [[#Densely packed decimal significand field|decimal encoding]], the 16-digit significand is represented as a decimal coded positive integer, based on [[densely packed decimal]] (DPD) with 5 groups of 3 digits (except the most significant digit encoded specially) are each represented in declets (10-bit sequences). This is pretty efficient, because 2<sup>10</sup> = 1024, is only little more than needed to still contain all numbers from 0 to 999.
exponent field consists of the 10 bits following the sign bit, and the
sigificand are the remaining 53 bits.
 
Both alternatives provide exactly the same set of representable numbers: 16 digits of significand and {{math|size=100%|1=3 × 2<sup>8</sup> = 768}} possible decimal exponent values. (All the possible decimal exponent values storable in a [[binary64]] number are representable in decimal64, and most bits of the significand of a binary64 are stored keeping roughly the same number of decimal digits in the significand.)
s 00eeeeeeee TTTtttttttttttttttttttt tttttttttttttttttttttttttttttt
s 01eeeeeeee TTTtttttttttttttttttttt tttttttttttttttttttttttttttttt
s 10eeeeeeee TTTtttttttttttttttttttt tttttttttttttttttttttttttttttt
 
In both cases, the most significant 4 bits of the significand (which actually only have 10 possible values) are combined with two 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. BID and DPD use different bits of the combination field for that.
This includes representation of [[subnormal numbers]].
 
In the cases of Infinity and NaN, all other bits of the encoding are ignored. Thus, it is possible to initialize an array to Infinities or NaNs by filling it with a single byte value.
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.
 
=== Binary integer significand field ===
s 11 00eeeeeeee (100)Ttttttttttttttttttttt tttttttttttttttttttttttttttttt
This format uses a binary significand from 0 to {{math|size=100%|1=10<sup>16</sup> − 1 = {{gaps|9|999|999|999|999|999}} = 2386F26FC0FFFF<sub>16</sub> = {{gaps|1000|1110000110|1111001001|1011111100|0000111111|1111111111<sub>2</sub>}}.}}The encoding, completely stored on 64 bits, can represent binary significands up to {{math|size=100%|1=10 × 2<sup>50</sup> − 1 = {{gaps|11|258|999|068|426|239}} = 27FFFFFFFFFFFF<sub>16</sub>,}} but values larger than {{math|size=100%|1=10<sup>16</sup> − 1}} are illegal (and the standard requires implementations to treat them as 0, if encountered on input).
s 11 01eeeeeeee (100)Ttttttttttttttttttttt tttttttttttttttttttttttttttttt
s 11 10eeeeeeee (100)Ttttttttttttttttttttt tttttttttttttttttttttttttttttt
 
As described above, the encoding varies depending on whether the most significant {{val|4|u=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>).
Note that the "11" 2-bit sequence after sign bit indicates that there is an ''implicit'' "100" 3-bit
lead sequence in the true 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 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.
 
If the 2 after the sign bit are "00", "01", or "10", then the exponent field consists of the {{val|10|u=bits}} following the sign bit, and the significand is the remaining {{val|53|u=bits}}, with an implicit leading {{val|0|u=bit}}. This includes [[subnormal numbers]] where the leading significand digit is 0.
The true significand is limited to
 
If the {{val|2|u=bits}} after the sign bit are "11", then the 10-bit exponent field is shifted {{val|2|u=bits}} to the right (after both the sign bit and the "11" bits thereafter), and the represented significand is in the remaining {{val|51|u=bits}}. In this case there is an implicit (that is, not stored) leading 3-bit sequence "100" for the MSB bits of the true significand (in the remaining lower bits ''ttt...ttt'' of the significand, not all possible values are used).
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>
 
{| class="wikitable" style="text-align:left; border-width:0;"
If the represented significand value, including the "100" implicit lead bits when the sign bit
|+ BID Encoding
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).
! colspan="13" | Combination Field
! rowspan="2" |
! rowspan="2" | Exponent
! rowspan="2" |Significand / Description
|-
! g12 !! g11 !! g10 !! g9 !! g8 !! g7 !! g6 !! g5 !! g4 !! g3 !! g2
!g1
!g0
|-
| colspan="16" |combination field not! starting with '11', bits ab = 00, 01 or 10
|-
| style="font-family:monospace; background:#cedff2;" | '''a''' || style="font-family:monospace; background:#cedff2;" | '''b''' || style="font-family:monospace; background:#cedff2;" | '''c''' || style="font-family:monospace; background:#cedff2;" | '''d''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cef2e0;" | '''e''' || style="font-family:monospace; background:#cef2e0;" |'''f''' || style="font-family:monospace; background:#cef2e0;" |'''g'''
| || style="font-family:monospace; background:#cedff2;" | '''abcdmmmmmm''' || style="background:#cef2e0;" |{{mono|(0)'''efgtttttttttttttttttttttttttttttttttttttttttttttttttt'''}}
Finite number with small first digit of significand (0&nbsp;..&nbsp;7).
|-
| colspan="16" |combination field starting with '11', but not 1111, bits ab = 11, bits cd = 00, 01 or 10
|-
| 1 || 1 || style="font-family:monospace; background:#cedff2;" | '''c'''|| style="font-family:monospace; background:#cedff2;" | '''d''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''e''' || style="font-family:monospace; background:#cedff2;" | '''f''' || style="font-family:monospace; background:#cef2e0;" | '''g'''
| || style="font-family:monospace; background:#cedff2;" | '''cdmmmmmmef''' || style="background:#cef2e0;" |{{mono|'''100gtttttttttttttttttttttttttttttttttttttttttttttttttt'''}}
Finite number with big first digit of significand (8 or 9).
|-
| colspan="16" |combination field starting with '1111', bits abcd = 1111
|-
| 1 || 1 || 1 || 1 || 0 || colspan="8" |
| rowspan="3" | || || ±Infinity
|-
| 1 || 1 || 1 || 1 || 1 ||0
| colspan="7" |
|
| quiet NaN
|-
|1
|1
|1
|1
|1
|1
| colspan="7" |
|
|signaling NaN (with payload in significand)
|}
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 {{gaps|8|000|000|000|000|000}} is encoded as binary {{gaps|0111|0001101011|1111010100|1001100011|0100000000|0000000000}}<sub>2</sub>, with the leading {{val|4|u=bits}} encoding 7; the first significand which requires a 54th bit is {{math|size=100%|1=2<sup>53</sup> = {{gaps|9|007|199|254|740|992}}.}} The highest valid significant is {{gaps|9|999|999|999|999|999}} whose binary encoding is
{{gaps|(100)0|1110000110|1111001001|1011111100|0000111111|1111111111}}<sub>2</sub> (with the 3 most significant bits (100) not stored but implicit as shown above; and the next bit is always zero in valid encodings).
 
In the above cases, the value represented is
 
: {{math|1=(−1)<sup>sign</sup> × 10<sup>exponent−398</sup> × significand}} <!-- Remember, significand is defined as an integer: 0 <= significand < 10^16 -->
<math>(-1)^\text{signbit}\times 10^{\text{exponentbits}_2-383}\times \text{truesignificand}_2</math>
 
If the fivefour bits after the sign bit are "111101111" then the value is an [[infinity]] or a NaN, as described above:
(compare the [[extended real number line]]),
with the sign indicated by the sign bit. The remaining 58 bits are ignored.
 
s0 11110 xxx...x an +infinity
1 11110 xx...x -infinity
 
If x the11111 six0x...x bits after the sign bit are 111110, the value is a quiet [[NaN]].
x 11111 1x...x a signalling NaN
The sign bit and the remaining bits after this special sequence have no meaningful interpretation.
 
s 111110 x...x a quiet NaN
 
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.
 
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]] (DPD) encoding.
 
The leading {{val|2|u=bits}} of the exponent and the leading digit (3 or {{val|4|u=bits}}) of the significand are combined into the five bits that follow the sign bit.
For the alternative using DPD encoding for most of the significand, the position
of the exponent part and significand parts do not move, but the implicit
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 last {{val|50|u=bits}} are the significand continuation field, consisting of five 10-bit ''[[declet (computing)|declet]]s''.<ref name="Muller_2010">{{cite book |author-last1=Muller |author-first1=Jean-Michel |author-last2=Brisebarre |author-first2=Nicolas |author-last3=de Dinechin |author-first3=Florent |author-last4=Jeannerod |author-first4=Claude-Pierre |author-last5=Lefèvre |author-first5=Vincent |author-last6=Melquiond |author-first6=Guillaume |author-last7=Revol |author-first7=Nathalie|author7-link=Nathalie Revol |author-last8=Stehlé |author-first8=Damien |author-last9=Torres |author-first9=Serge |title=Handbook of Floating-Point Arithmetic |year=2010 |publisher=[[Birkhäuser]] |edition=1 |isbn=978-0-8176-4704-9<!-- print --> |doi=10.1007/978-0-8176-4705-6 |lccn=2009939668<!-- |isbn=978-0-8176-4705-6 (online), ISBN 0-8176-4704-X (print) -->|url=https://cds.cern.ch/record/1315760 }}</ref> Each declet encodes three decimal digits<ref name="Muller_2010"/> using the DPD encoding.
The eight bits before the significand field is the exponent field.
 
If the first two bits after the sign bit are "00", "01", or "10", then those are the leading bits of the exponent, and the three bits "cde" after that are interpreted as the leading decimal digit (0 to 7):
exponent field has those two bits as (semi)implicit lead bits.
The three bits after the "00", "01", or "10" bits are interpreted as
the lead decimal digit (0 to 7).
 
If the first two bits after the sign bit are "11", then the second 2-bits are the leading bits of the exponent, and the next bit "e" is prefixed with implicit bits "100" to form the leading decimal digit (8 or 9):
s 00 mmm (00)eeeeeeee (mmm)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
s 01 mmm (01)eeeeeeee (mmm)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
s 10 mmm (10)eeeeeeee (mmm)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
 
IfThe remaining two combinations (11 110 and 11 111) of the 45-bit bitsfield after the sign bit are "1100",used "1101",to orrepresent "1110",±infinity thenand theNaNs, respectively.
exponent field has last two bits of those four bits as (semi)implicit lead bits.
The bit just before the exponent field is prefixed with "100" and is
interpreted as the lead digit for the significand (8 or 9).
 
{| class="wikitable" style="text-align:left; border-width:0;"
s 1100 m (00)eeeeeeee (100m)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
|+ DPD Encoding
s 1101 m (01)eeeeeeee (100m)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
|-
s 1110 m (10)eeeeeeee (100m)[tttttttttt][tttttttttt][tttttttttt][tttttttttt][tttttttttt]
! colspan="13" | Combination Field
! rowspan="2" |
! rowspan="2" | Exponent
! rowspan="2" |Significand / Description
|-
! g12 !! g11 !! g10 !! g9 !! g8 !! g7 !! g6 !! g5 !! g4 !! g3 !! g2
!g1
!g0
|-
| colspan="16" |combination field not! starting with '11', bits ab = 00, 01 or 10
|-
| style="font-family:monospace; background:#cedff2;" | '''a''' || style="font-family:monospace; background:#cedff2;" | '''b''' || style="font-family:monospace; background:#cef2e0;" | '''c''' || style="font-family:monospace; background:#cef2e0;" | '''d''' || style="font-family:monospace; background:#cef2e0;" | '''e''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m'''
| || style="font-family:monospace; background:#cedff2;" | '''abmmmmmmmm'''|| style="background:#cef2e0;" |{{nowrap|{{mono|(0)'''cde tttttttttt tttttttttt tttttttttt tttttttttt tttttttttt'''}}}}
Finite number with small first digit of significand (0&nbsp;…&nbsp;7).
|-
| colspan="16" |combination field starting with '11', but not 1111, bits ab = 11, bits cd = 00, 01 or 10
|-
| 1 || 1 || style="font-family:monospace; background:#cedff2;" | '''c''' || style="font-family:monospace; background:#cedff2;" | '''d''' || style="font-family:monospace; background:#cef2e0;" | '''e''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m''' || style="font-family:monospace; background:#cedff2;" | '''m'''
| || style="font-family:monospace; background:#cedff2;" | '''cdmmmmmmmm'''|| style="background:#cef2e0;" |{{nowrap|{{mono|'''100e tttttttttt tttttttttt tttttttttt tttttttttt tttttttttt'''}}}}
Finite number with big first digit of significand (8 or 9).
|-
| colspan="16" |combination field starting with '1111', bits abcd = 1111
|-
| 1 || 1 || 1 || 1 || 0 || colspan="8" |
| rowspan="3" | || || ±Infinity
|-
| 1 || 1 || 1 || 1 || 1 ||0
| colspan="7" |
|
| quiet NaN
|-
|1
|1
|1
|1
|1
|1
| colspan="7" |
|
|signaling NaN (with payload in significand)
|}
 
The DPD/3BCD transcoding for the declets is given by the following table. b9...b0 are the bits of the DPD, and d2...d0 are the three BCD digits.
The declets of the significand field are interpreted according to the
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.
b9...b0 are the bits of the DPD, and d2...d0 are the three BCD digits.
 
{{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 [[don't care|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 {{math|size=100%|1=8 × 3 = 24}} non-standard encodings fill in the gap between {{math|size=100%|1=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 ==
* [[IEEE 754-2008|IEEE Standard for Floating-Point Arithmetic (IEEE 754)]]
* [[ISO/IEC 10967]], Language Independent Arithmetic
* [[Primitive data type]]
* [[D notation (scientific notation)]]
 
== References ==
Line 144 ⟶ 185:
[[Category:Computer arithmetic]]
[[Category:Data types]]
[[Category:Floating point types]]