Welcome to the General Decimal Arithmetic website, which is
now hosted at speleotrove.com.
The page and file names here have not been changed from the names
used on the previous website, www2.hursley.ibm.com.
Most computers today support binary floating-point in hardware.
While suitable for many purposes, binary floating-point arithmetic
should not be used for financial, commercial, and user-centric
applications or web services because the decimal data used in these
applications cannot be represented exactly using binary floating-point.
(See the Frequently Asked Questions pages for
an explanation of this, and several examples.)
The problems of binary floating-point can be avoided by using base 10
(decimal) exponents and preserving those exponents where possible.
This site describes a decimal arithmetic which achieves the necessary
results and is suitable for both hardware and software
It brings together the relevant concepts from a number of
ANSI, IEEE, ECMA, and ISO standards, and
conforms to the decimal formats and arithmetic in the
754 standard (‘754-2008’)
by the IEEE in August 2008, and the
standard, published by ISO in July 2011.
The decimal-encoded formats and arithmetic described in the new
standard now have many implementations in hardware and software
(see links below), including:
the hardware decimal floating-point unit in the
the firmware (with assists) in the
System z9 mainframe, and the hardware decimal floating-point
unit in the
z10 mainframe (see
paper for details)
Decimal Floating Point Arithmetic hardware
(see also their
presentation for some details)
Fujitsu’s decimal instructions in the
SPARC64 X processor
charts 5 & 6).
for AIX, Linux and
UNIX, and Windows,
PL/I for z/OS; IBM is also adding support to many other software
products including z/VM V5.2, System i/OS, the dbx debugger, and Debug
Tool Version 8.1
7.1, which includes the new DECFLOAT datatype in ABAP, with
for hardware decimal floating-point on Power6
GCC 4.2 and later includes
support for the proposed ISO C extensions for decimal floating point.
The combination of formats and arithmetic defined here and in the
IEEE 754 standard describe a new decimal data type, in various sizes.
Notably, this single data type can be used for integer, fixed-point,
and floating-point decimal arithmetic, and the design permits
compatible fixed-size and arbitrary-precision implementations.
Further, most existing numeric data in commercial databases are
stored in a decimal form (one or two digits per byte), which can
be converted to and from the decimal-encoded formats efficiently
The main features of the arithmetic are summarized
For the background and rationale for the design of the arithmetic,
see Decimal Floating-Point:
Algorism for Computers in the Proceedings of the 16th IEEE
Symposium on Computer Arithmetic (Cowlishaw, M. F., 2003).
Reproduced with permission from IBM © Copyright 1997, 2008 by
International Business Machines Corporation.
Copyright © Mike Cowlishaw 1981, 2013.
Documentation and downloads
Here you will find documentation and downloads for
fixed-size decimal formats (encodings) and
the decNumber reference implementation,
the DFPAL PowerPC abstraction layer,
and the language-independent testcases.
This first document describes the decimal arithmetic in a
language-independent and encoding-independent manner:
|Decimal floating-point arithmetic, with unrounded and integer
arithmetic as a subset (IEEE 754 + IEEE 854 + ANSI X3.274 +
ECMA 334 + Java[TM] 5).
This specification forms the basis for a number
of implementations, and also describes the
decimal arithmetic in the new IEEE 754 standard.
The next document describes three decimal-encoded formats
designed by the
IEEE 754 Revision
Committee, accepted in January 2003 (‘Strawman 4d’),
and now part of the revised IEEE 754 standard.
Also here are some performance measurements comparing operations
using various encodings.
|Concrete decimal formats (bit encodings) suitable for
hardware or software implementation of native decimal
datatypes; these provide up to 7, 16, or 34 digits of
|Performance measurements on three implementations
that support the IEEE 754 decimal formats.
Java[TM] classes which
illustrate the decimal encoding of decimal floating-point
numbers, and the corresponding decoding.
(The earlier ‘Strawman 1’ proposal, implemented as
decSingle and decDouble in early versions of the decNumber
package, is available for historical interest in
See also: A
Decimal Floating-Point Specification, Schwarz et al.,
15th IEEE Symposium on Computer Arithmetic
The decNumber package, an implementation of
the specifications in ANSI C, provides a reference implementation
for both the arithmetic and the encodings. It includes both an
arbitrary-precision implementation and a (much faster)
decFloats implementation that uses the IEEE 754 decimal
encodings directly to implement decSingle, decDouble, and decQuad
The package is available under two
free open source licenses (the ICU license is
the simpler and the less restrictive), and is suitable for
little-endian or big-endian systems which support 32-bit (or
wider) integers. It is currently in use on dozens of different
platforms, including mainframes, PowerPC, ARM-based microcontrollers
and tablets, x86, and over 20 varieties of Unix.
|Describes the decNumber package, including a User’s Guide
section with several examples.
(Note that the documentation here may be a more
recent version than some versions of downloadable code. If such is the
case, check the changes list in the Appendix to determine
if this document applies.)
||Known bugs and fixes since 3.56, 2007.10.12.
|International Components for Unicode (ICU)
The source code (.h and .c
files), together with the examples, the
ICU license, and the documentation in PDF format.
(The latest package is also mirrored
|GPL open source
decNumber C code
|‘decNumber C code’ links to the open source code
(.h and .c files), part of
the GCC project (GPL license).
‘decExamples.zip’ contains the example
files referred to in the documentation and also the
readme.txt file which has suggestions on how to compile
and run the examples.
More implementations of the arithmetic are listed
Punit Shah’s DFPAL package provides an abstraction
layer for AIX, i5/OS (under PASE), and Linux on Power that will
automatically use PowerPC (Power6) Decimal Floating-Point hardware if
available (or will otherwise use decNumber for decimal calculations).
In addition to arithmetic operations and various utilities, DFPAL
also provides conversions between decimal floating point formats
and many other programming language intrinsic data types such as
binary floating point and integers.
Finally, the following language-independent testcases can be used
for testing implementations:
|Describes the testcase file format, testcase coverage, and
|The extended (dectest.zip) and subset
(dectest0.zip) testcase files (containing more than
These cover all the operations and conversions described in
the specifications, and include tests for the decimal
See also the
Haifa test suite (FPGen), and
operations debugging and verification page.
Summary of the arithmetic
The decimal arithmetic described here combines the requirements of both
fixed-point and floating-point arithmetic, giving the following
The arithmetic permits a single representation of decimal numbers,
whether they be integers, fixed-point (scaled), or floating-point;
this minimizes conversion overheads.
The arithmetic was designed as a decimal extended floating-point
arithmetic, directly implementing the rules that people are taught at
school. Up to a given working precision, exact unrounded results are
given when possible (for instance, 0.9 ÷ 10 gives 0.09, not
0.089999996), and trailing zeros are correctly preserved in most
operations (1.23 + 1.27 gives 2.50, not 2.5). Where results would
exceed the working precision, floating-point rules apply.
The working precision of the arithmetic is not necessarily
determined by the representation, but may be freely selectable
within the limits of the representation as required for the problem
being solved. Implementations may provide very high precision if
The arithmetic operations are robust; integers will never
‘wrap’ from positive to negative when being
incremented, and, if required, ill-defined or out-of-range results
immediately throw exceptions.
The concept of a context for operations is explicit. This
allows application-global rules (such as precision, rounding
mode, and exception handling) to be easily implemented and
modified. This aids testing and error analysis, as well as
The core arithmetic was developed in 1980–1981, based directly
on user feedback and requirements, and in consultation with
professional mathematicians and data processing experts. It has been
heavily used for over 27 years without problems, and was reviewed in
depth and published by the X3J18 committee for the ANSI
The same arithmetic has been included
in Java[TM] 5, through JSR 13, and in
several other languages (see the links below).
More recently, the core arithmetic has been extended to include the
special values and other requirements of IEEE 854 (the
radix-independent generalization of IEEE 754-1985). This combined
arithmetic meets commercial, scientific, mathematical, and enginering
requirements, and is now included in the
The links below provide background and related information.
Background & Rationale
Software with hardware support
Standards and Specifications
Fujitsu’s decimal Densely Packed Decimal and NUMBER
support instructions in the
SPARC64 X processor announced at Hot Chips 24, August 2012.
(See charts 5 & 6 of this
Decimal Floating Point Arithmetic
Cores Family product page and
Cores Family presentation, and also their
Parser-Coder software tool
Decimal floating-point support on the IBM System z10
processor – by
Eric Schwarz, John Kapernick, and Mike Cowlishaw
(January 2009) – describes decimal floating-point
hardware in, and supporting software for,
the new IBM System
Charles Webb’s IBM z6 –
The Next-Generation Mainframe Microprocessor presentation
at Hot Chips 19,
(details of the decimal floating-point unit in
the z6 are on charts 7, 19, and 20)
PC (Power6) announcement; see also the
Instruction Set Architecture Decimal Floating Point
(Book 1, Chapter 5), and Bradley McCredie’s
(details of the decimal floating-point unit in
Power6 are on charts 12–14)
System z9 announcement; see also
floating-point in z9: An implementation and testing perspective and the
Decimal-Floating-Point Architecture for IBM System z processors
The new IEEE
754 standard (‘754-2008’) was published
by the IEEE in August 2008, and is available from
Xplore. It includes decimal floating-point
formats (as described above)
and arithmetic on those formats (also described
This replaces the earlier IEEE 754-1985 (Binary
Floating-Point) and IEEE 854 (Radix-independent
JTC1/SC22/WG14 – Programming Language C and
JTC1/SC22/WG21 – Programming Language C++
committees are jointly working on decimal-floating point
additions; the work items are TR 24732 and TR 24733,
Draft Technical Report, and
DECFLOAT Decimal floating-point data type
- Java Specification Request 13
Decimal Arithmetic Enhancement for Java implements most
of the IEEE 754 decimal arithmetic, and extends it to arbitrary precision
floating-point in Java 6 – Best practices)
ANSI X3.274-1996 [Rexx] standard, errata, etc.
includes the decimal arithmetic which was the inspiration for much
of the work described on this page; the final version is
available from the ANSI
C# Language Specification standard [ECMA 334, with decimal
floating-point data type] and the
Common Language Infrastructure (CLI) standard [ECMA
335, with the System.Decimal class]; these define a subset of
the IEEE 754 arithmetic; recent work has extended these standards
to permit the use of the full IEEE 754 decimal-encoded
- The ISO/IEC
1989:2002 – COBOL standard (this specifies
32-digit decimal floating-point for calculations)
- The Python 2.4
95 decimal types (Part 1, 3.3.3), and
95 decimal arithmetic (Part 3, Annex F.1)
Perl 6 decimal BigNum definition
- XML Schema Part
2: Datatypes (see §3.2.5, decimal data type), and the
precisionDecimal type in
XML Schema 1.1 Part 2: Datatypes (see §3.3.4)
- IBM System z Preliminary
- Power.org Power
Instruction Set Architecture Decimal Floating Point (see Book 1, Chapter 5)
- IBM ESA/390 Principles of Operation,
Decimal Arithmetic Instructions (BCD integer arithmetic)
- A summary of the Densely Packed Decimal
encoding used in the decimal-encoded formats described
above; see also
Bonten’s summary for a different description
- A summary of Chen-Ho decimal encoding
- European Commission:
The Introduction of the Euro and the Rounding of Currency
Council Regulation (EC) No 1103/97 of 17 June 1997 on certain provisions relating
to the introduction of the euro
Related Decimal Links
Floating-point starter links
Multi-precision binary floating-point
... and finally ...
Hossam Fahmy’s page on
operations debugging and verification – Amr
Abdel-Fatah Sayed-Ahmed’s research, papers, and decimal
arithmetic test vectors.
Paul Dale’s decimal
firmware source code for some recent HP business
calculators, including a real and complex mathematics library.
Mark Erle’s dissertation:
Algorithms and Hardware Designs for Decimal Multiplication
floating-point in Java 6 – Best practices, by
Marcel Mitran, Ivan Sham, and Levon Stepanian
to Leverage Decimal Floating-Point unit on POWER6 for Linux article
I love ECMAScript 4 real decimals article
The data type of the future article, which explains
the new decimal floating-point data type in DB2 for Linux,
UNIX, and Windows
Decimal Floating Point article, with examples and code
Janis Johnson and Steve Carlough’s
and Decimal Floating Point presentation
(Power Architecture Developer Conference,
Haifa test suite (FPGen) for IEEE 754 decimal floating-point
Parser-Coder for parsing the
Haifa FPGen testcases
evolving BigDecimal in Java
on DB2 Hardware Exploitation of Decimal Arithmetic on POWER6
classes for Java
The Univerity of Wisconsin at Madison
Floating-Point Arithmetic Research page
press article referring to decimal floating-point hardware in
the IBM Power6 processor
Worst Cases for the Exponential Function in the IEEE 754r
Zimmermann et al. (pre-print; also see
for the latest results)
- A Decimal Floating-Point
Specification, Eric Schwarz et al., from Arith15
- Mozilla ‘rounding
bug’ (note the duplicates)
- Search for
Patriot Missile Failure (tenths of a second × 0.1)
Arithmetic calculations with decimals, Encyclopaedia Britannica
A Calculated Look at Fixed-Point Arithmetic, Robert Gordon
BCD Arithmetic, a tutorial, Douglas W. Jones
(includes 6-bit algorithms)
Arithmetic chapter from The Art of  Assembly
Language Programming by Randall Hyde
floating point in .Net article
Computer Formats pages
for System z packed decimal data
Hewlett Packard 71B Calculator
(IEEE 854 compliant)
- Gary Darby’s
Big [decimal] Floating Point package
- Richard Brent’s
User’s Guide, Fourth edition, 1981.
Ada Decimal Arithmetic and Representations, Ada Information
- Rogue Wave decimal
and Currency for Java
- Clive “Max” Maxfield’s articles and book:
- Bill Rossi’s
Decimal Floating Point
Java class library (base 10000)
The [Atari Decimal] Floating Point Arithmetic Package, C. Lisowski.
- The Microsoft
Arithmetics for AVR 8-bit RISC
John Savard’s Base-26 Armor
- Harry J. Smith’s
variable precision calculator
- Touch Technologies Inc’s
Precision Math in SheerPower 4GL
World’s Smallest Abacus
- Tim Robinson’s
Difference Engine #1
- Florida State University’s
- Henry Baker’s
How to Steal from a Limited Private Account
- The Apple WebObjects
- The Apache Derby database sub-project
datatypes and scale rules
and Foreign Exchange page, and currency links
- Don North’s post on
11 decimal hardware (Commercial Instruction Set, CIS)
table attacks for PIN cracking
- Jim Horning’s page about
to Decimal Conversion on the Bendix G-15.
Please send any comments or corrections to
Mike Cowlishaw (mfc),
email@example.com; see also
Reproduced with permission from IBM © Copyright 1997, 2008 by
International Business Machines Corporation.
Parts © Mike Cowlishaw 1997, 2013.
Java is a trademark of Sun Microsystems Inc. and Oracle.