Decimal Encoding Specification, version 1.01
Copyright (c) IBM Corporation, 2009. All rights reserved. ©
7 Apr 2009
[previous | contents | next]

Overview

(This overview is not part of the specification.)

This document describes decimal encodings for decimal numbers. These encodings allow for a range of positive and negative values (including both normal and subnormal numbers), together with values of ±0, ±Infinity, and Not-a-Number (NaN).

Three formats of decimal numbers are described:

The finite numbers are defined by a sign, an exponent (which is a power of ten), and a decimal integer coefficient. The value of a finite number is given by (–1)sign × coefficient × 10exponent. For example, if the sign had the value 1, the exponent had the value –1, and the coefficient had the value 25, then the value of the number is –2.5.

This dual integer description of numbers permits redundant encodings of some values. For example, if the sign had the value 1, the exponent had the value –2, and the coefficient had the value 250, then the numerical value of this number is also –2.5.

The advantage of this representation is that it exactly matches the definition of decimal numbers used in almost all databases, programming languages, and applications. This in turn allows a decimal arithmetic unit to support not only the floating-point arithmetic used in languages such as Java and C# but also the strongly-typed fixed-point and integer arithmetic required in databases and other languages.

The cost of the redundant encodings is approximately a 17% reduction in possible exponent values – however, because the base is 10, the exponent range is always greater than that of the IEEE 754 binary format of the same size.

In the encoding of these dual-integer numbers, the sign is a single bit, as for IEEE 754 binary numbers. The exponent is encoded as an unsigned binary integer from which a bias is subtracted to allow both negative and positive exponents. The coefficient is an unsigned decimal integer, with each complete group of three digits encoded in 10 bits (this increases the precision available by about 15%, compared to simple binary coded decimal).

Given the length of the coefficient and possible values for the encoded exponent, the maximum positive exponent (Emax) and bias can be derived, as described in Appendix A.

Calculating the values leads to the following results for the three formats:
Format decimal32 decimal64 decimal128
Coefficient length in digits 7 16 34
Maximum Exponent (Emax) 96 384 6144
Minimum Exponent (Emin) –95 –383 –6143
Bias 101 398 6176
For the decimal32 format, the largest normal number is 9.999999 × 10Emax The coefficient and exponent for some sample positive numbers in this format are:
 
Number
Dual-integer representation Encoded
exponent
coefficient exponent
9.999999 × 10Emax 9999999 +90 191
1.234567 × 10Emax 1234567 +90 191
1.23 × 10Emax 1230000 +90 191
1 × 10Emax 1000000 +90 191
12345 12345 0 101
1 1 0 101
1.23 123 –2 99
123.45 12345 –2 99
1 × 10Emin 1 –95 6
1.000000 × 10Emin 1000000 –101 0
1.000001 × 10Emin 1000001 –101 0
0.000001 × 10Emin 1 –101 0
Of these positive numbers, the number 9.999999 × 10Emax (which has no redundant encoding) is the largest normal number, the number 1 × 10Emin (and its redundant encodings) is the smallest normal number, and 0.000001 × 10Emin (which has no redundant encoding) is the smallest subnormal number.

Note that numbers with the same ‘scale’ (such as 1.23 and 123.45) have the same encoded exponent.

As shown in the first table, each format has a coefficient whose length is a multiple of three, plus one. One digit of the coefficient (the most significant) cannot be included in a 10-bit group and instead is combined with the two most significant digits of the exponent into a 5-bit combination field. This scheme is more efficient than keeping the exponent and coefficient separated, and increases the exponent range available by about 50%.

The combination field requires 30 states out of a possible 32 for the finite numbers; the other two states are used to identify the special values. This localization of the special values means that only the first few bits of a number have to be inspected in order to determine whether it is finite or is a special value. Further, bulk initialization of storage to values of ±0, NaN, or ±Infinity can be achieved by simple byte replication.


[previous | contents | next]