Decimal Arithmetic Specification, version 1.08 Copyright (c) IBM Corporation, 2003. All rights reserved. © | 8 Jan 2003
[previous | contents | next]

# Scope

### Objectives

This document defines a general purpose decimal arithmetic. A correct implementation of this specification will conform to the decimal arithmetic defined in ANSI/IEEE standard 854-1987,[1] except for some minor restrictions, and will also provide unrounded decimal arithmetic[2] and integer arithmetic as proper subsets.

### Inclusions

This specification defines the following:

- Constraints on the values of decimal numbers
- Operations on decimal numbers, including
  - Required conversions between string and internal representations of numbers
  - Arithmetical operations on decimal numbers (addition, subtraction, etc.)
- Context information which alters the results of operation, and default contexts.
- Exceptional conditions, such as overflow, underflow, undefined results, and other exceptional situations which may occur during operations.

### Exclusions

This specification does not define the following:

- Concrete representations (storage format) of decimal numbers[3]
- Concrete representations (storage format) of context information
- The means by which operations are effected

### Restrictions

This specification deviates from the requirements of IEEE 854 in the following respects:

1. The remainder-near operator is restricted to those values where the intermediate integer can be represented in the current precision.[4]
2. This specification does not require that values returned after overflow and underflow change if the exception trap-enabler is set, and the criteria for underflow similarly do not change if its trap-enabler is set (the Subnormal condition has been added to allow the alternative underflow condition to be detected).[5]
3. The string representations of NaN values are `"NaN"` and `"sNaN"`, instead of just `"NaN"` with an optional sign.[6]

Note that all other requirements of IEEE 854 (such as subnormal numbers and the negative zero) are included in this specification.

Footnotes:

[1] | IEEE 854-1987 – IEEE Standard for Radix-Independent Floating-Point Arithmetic, The Institute of Electrical and Electronics Engineers, Inc., New York, 1987.
[2] | Sometimes called ‘fixed-point’ decimal arithmetic.
[3] | Some proposed representations can be found in: `http://www2.hursley.ibm.com/decimal/deccode.pdf`
[4] | This is because the conventional implementation of this operator would be unacceptably long-running for the range of numbers allowed by this specification (with up to nine digits of exponent). For restricted-range numbers, an implementation can easily be made to conform to IEEE 854 in this respect.

[5]

This follows the current proposals of the IEEE 754R committee which is revising IEEE 754 and IEEE 854. Dependence on the trap-enabler setting is difficult to make thread-safe, and also the IEEE 854 definition does not generalize to the power operator (the required replacement value may itself overflow or underflow). An implementation may provide the IEEE values, if feasible, to a trap handler via some separate mechanism, but this is not required by this specification.

[6] | This follows the current proposals of the IEEE 754R committee which is revising IEEE 754 and IEEE 854.

[previous | contents | next]