IEEE 754-2008 Encoding
The IEEE 754-2008 standard defines 32-, 64- and 128-bit decimal floating-point representations. Like the binary floating-point formats, the number is divided into a sign, and exponent, and a significand. Unlike binary floating-point, numbers are not necessarily normalized; values with few significant digits have multiple possible representations: 1×102=0.1×103=0.01×104, etc. When the significand is zero, the exponent can be any value at all.
decimal32 | decimal64 | decimal128 | decimal(32k) | Format |
---|---|---|---|---|
1 | 1 | 1 | 1 | Sign field (bits) |
5 | 5 | 5 | 5 | Combination field (bits) |
6 | 8 | 12 | w = 2×k + 4 | Exponent continuation field (bits) |
20 | 50 | 110 | t = 30×k−10 | Coefficient continuation field (bits) |
32 | 64 | 128 | 32×k | Total size (bits) |
7 | 16 | 34 | p = 3×t/10+1 = 9×k−2 | Coefficient size (decimal digits) |
192 | 768 | 12288 | 3×2w = 48×4k | Exponent range |
96 | 384 | 6144 | Emax = 3×2w−1 | Largest value is 9.99...×10Emax |
−95 | −383 | −6143 | Emin = 1−Emax | Smallest normalized value is 1.00...×10Emin |
−101 | −398 | −6176 | Etiny = 2−p−Emax | Smallest non-zero value is 1×10Etiny |
The exponent ranges were chosen so that the range available to normalized values is approximately symmetrical. Since this cannot be done exactly with an even number of possible exponent values, the extra value was given to Emax.
Two different representations are defined:
- One with a binary integer significand field encodes the significand as a large binary integer between 0 and 10p−1. This is expected to be more convenient for software implementations using a binary ALU.
- Another with a densely packed decimal significand field encodes decimal digits more directly. This makes conversion to and from binary floating-point form faster, but requires specialized hardware to manipulate efficiently. This is expected to be more convenient for hardware implementations.
Both alternatives provide exactly the same range of representable values.
The most significant two bits of the exponent are limited to the range of 0−2, and the most significant 4 bits of the significand are limited to the range of 0−9. The 30 possible combinations are encoded in a 5-bit field, along with special forms for infinity and NaN.
If the most significant 4 bits of the significand are between 0 and 7, the encoded value begins as follows:
s 00 xxxx Exponent begins with 00, significand with 0mmm s 01 xxxx Exponent begins with 01, significand with 0mmm s 10 xxxx Exponent begins with 10, significand with 0mmmIf the leading 4 bits of the significand are binary 1000 or 1001 (decimal 8 or 9), the number begins as follows:
s 1100 xx Exponent begins with 00, significand with 100m s 1101 xx Exponent begins with 01, significand with 100m s 1110 xx Exponent begins with 10, significand with 100mThe leading bit (s in the above) is a sign bit, and 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.
The final combinations are used for infinities and NaNs, and are the same for both alternative encodings:
s 11110 x ±Infinity (see Extended real number line) s 111110 quiet NaN (sign bit ignored) s 111111 signaling NaN (sign bit ignored)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.
Read more about this topic: Decimal Floating Point