|
The decNumber Library, version 3.56
Copyright (c) IBM Corporation, 2007. All rights reserved. © | 12 Oct 2007 |
| [contents | next] |
The library fully implements the specification, and hence supports integer, fixed-point, and floating-point decimal numbers directly, including infinite, NaN (Not a Number), and subnormal values. Both arbitrary-precision and fixed-size representations are supported.
The arbitrary-precision code is optimized and tunable for common values (tens of digits) but can be used without alteration for up to a billion digits of precision and 9-digit exponents. It also provides functions for conversions between concrete representations of decimal numbers, including Packed BCD (4-bit Binary Coded Decimal) and three fixed-size formats of decimal floating-point. called decFloats.
The three fixed-size formats are also supported by three modules called decFloats, which have an extensive set of functions that work directly from the formats and provide arithmetical, logical, and shifting operations, together with conversions to binary integers, Packed BCD, and 8-bit BCD. Most of the functions defined in the proposed IEEE 754 revision (‘754r’)[2] are included, together with other functions outside the scope of that standard but essential for a decimal-only language implementation.
The core of the library is the decNumber module. This uses an arbitrary-precision decimal number representation designed for efficient computation in software and implements the arithmetic and logical operations, together with a number of conversions and utilities. Once a number is held as a decNumber, no further conversions are necessary to carry out arithmetic.
Most functions in the decNumber module take as an argument a decContext structure, which provides the context for operations (precision, rounding mode, etc.) and also controls the handling of exceptional conditions (corresponding to the flags and trap enablers in a hardware floating-point implementation).
The decNumber representation is variable-length and machine-dependent (for example, it contains integers which may be big-endian or little-endian).
In addition to the arbitrary-precision decNumber format, three fixed-size compact storage formats are provided for conversions and interchange.[3] These formats are endian-dependent but otherwise are machine-independent:
A fourth, machine-independent, Binary Coded Decimal (BCD) format is also provided:
The decimal32, decimal64, and decimal128 formats are also supported directly by three modules which can be used stand-alone (that is, they have no dependency on the decNumber module). These are:
| [1] | See http://www2.hursley.ibm.com/decimal/#arithmetic for details. |
| [2] | See http://grouper.ieee.org/groups/754/ |
| [3] | See http://www2.hursley.ibm.com/decimal/decbits.html for details of the formats. |
| [4] | Except for two which convert to or from a wider format. |
| [5] | American National Standard for Information Technology – Programming Language REXX, X3.274-1996, American National Standards Institute, New York, 1996. |
| [6] | IEEE 854-1987 – IEEE Standard for Radix-Independent Floating-Point Arithmetic, The Institute of Electrical and Electronics Engineers, Inc., New York, 1987. |
| [7] | See http://grouper.ieee.org/groups/754/ ; this revision is in ballot, but is still subject to change. |