Movatterモバイル変換


[0]ホーム

URL:




think 10
Welcome to the General Decimal Arithmetic website, which isnow hosted atspeleotrove.com.The page and file names here have not been changed from the namesused 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 arithmeticshould not be used for financial, commercial, and user-centricapplications or web services because the decimal data used in theseapplications cannot be represented exactly using binary floating-point.(See theFrequently Asked Questions pages foran 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 necessaryresults and is suitable for both hardware and softwareimplementation.It brings together the relevant concepts from a number ofANSI, IEEE, ECMA, and ISO standards, andconforms to the decimal formats and arithmetic in theIEEE754 standard (‘754-2008’)publishedby the IEEE in August 2008, and theISO/IEC/IEEE 60559:2011standard, published by ISO in July 2011. IEEE 754-2008 is currentlyundergoing a minor revision.

The decimal-encoded formats and arithmetic described in the newstandard now have many implementations in hardware and software(seelinks below), including:

The combination of formats and arithmetic defined here and in theIEEE 754 and ISO/IEC/IEEE 60559:2011 standards describe a newdecimal 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 permitscompatible fixed-size and arbitrary-precision implementations.Further, most existing numeric data in commercial databases arestored in a decimal form (one or two digits per byte), which canbe converted to and from the decimal-encoded formats efficientlyand easily.

The main features of the arithmetic aresummarizedbelow.For the background and rationale for the design of the arithmetic,seeDecimal Floating-Point:Algorism for Computers in the Proceedings of the 16th IEEESymposium on Computer Arithmetic (Cowlishaw, M. F., 2003).

Parts of these decimal arithmetic pages are reproduced with permissionfrom IBM © Copyright 1997, 2008 by International Business MachinesCorporation.Copyright © Mike Cowlishaw 1981, 2015.


Here you will find documentation and downloads fordecimal arithmetic,fixed-size decimal formats (encodings) andtheir performance,thedecNumber reference implementation,theDFPAL PowerPC abstraction layer,and the language-independent testcases.

  1. This first document describes thedecimal arithmetic in alanguage-independent and encoding-independent manner:

    Specification
    [.html |.pdf]
    1.70
    Decimal floating-point arithmetic, with unrounded and integer arithmetic as a subset (IEEE 754 + IEEE 854 + ANSI X3.274 + ECMA 334 + Java 5).

  2. The next document describes three decimal-encodedformatsdesigned by theIEEE 754 RevisionCommittee, accepted in January 2003 (‘Strawman 4d’),and now part of the revised IEEE 754 standard.Also here are some performance measurements comparing operationsusing various encodings.

    Specification
    [.html |.pdf]
    1.01
    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 precision.
    Performance
    [.html |.pdf]
    1.12
    Performance measurements on three implementations that support the IEEE 754 decimal formats.
    Sample code
    [.html]
    1.00
    Java classes which illustrate the decimal encoding of decimal floating-point numbers, and the corresponding decoding.

  3. ThedecNumber package, an implementation ofthe specifications in ANSI C, provides areference implementationfor both the arithmetic and the encodings. It includes both anarbitrary-precision implementation and a (much faster)decFloats implementation that uses the IEEE 754 decimalencodings directly to implement decSingle, decDouble, and decQuaddatatypes.

    The package is available under twofree open source licenses (the ICU license isthe simpler and the less restrictive), and is suitable forlittle-endian or big-endian systems which support 32-bit (orwider) integers. It is currently in use on dozens of differentplatforms, including mainframes, PowerPC, ARM-based microcontrollersand tablets, x86, and over 20 varieties of Unix.

    Documentation
    [.html |.pdf]
    3.68
    Describes the decNumber package, including a User’s Guide section with several examples.
    Errata Known bugs and fixes since 3.56, 2007.10.12.recently updated
    International Components for Unicode (ICU)
    decNumber package in ICU
    decNumber .zip download
    3.68
    The ‘decNumber .zip download’ includes the source code (.h and.c files), together with the examples, theICU license, and the documentation in PDF format.
    GPL open source
    decNumber C code in GCC
    decNumber .zip download
    decExamples.zip
    3.53
    decNumber C code’ links to the open source code (.h and.c files), part of the GCC project (GPL license). The ‘decNumber .zip download’ also includes the source code,etc.decExamples.zip’ contains the example files referred to in the documentation and also thereadme.txt file which has suggestions on how to compile and run the examples.
    Patches
    decNumber368-patches-20210522.zip
    3.68
    The decNumber368-patches-20210522.zip file contains three.patch files, contributed by Matthew Hagerty. The patches are needed for the decNumber 3.68 code to compile cleanly with gcc 10.2.0.
    See the included.txt file and also Matthew Hagerty’sdecNumber github page for more information.

  4. Punit Shah’sDFPAL package provides an abstractionlayer for AIX, i5/OS (under PASE), and Linux on Power that willautomatically use PowerPC (Power6) Decimal Floating-Point hardware ifavailable (or will otherwise use decNumber for decimal calculations).

    In addition to arithmetic operations and various utilities, DFPALalso provides conversions between decimal floating point formatsand many other programming language intrinsic data types such asbinary floating point and integers.

    Documentation
    [.html |as .zip]
    2.20
    The DFPAL User’s guide with overview, examples, compilation instructions, FAQ,etc.
    Download
    DFPAL.zip
    DFPAL.tar.gz
    2.20
    The DFPAL source code (.h and.c files), together with the examples, the International Components for Unicode (ICU) license, the documentation in HTML format,etc.

  5. Finally, the following language-independent testcases can be usedfor testing implementations; these are part of the decNumber packagedocumentation, and are also covered by theICU license:

    Documentation
    [.html |.pdf]
    2.44
    Describes the testcase file format, testcase coverage, and testcase sources.
    Download
    dectest.zip
    dectest0.zip
    2.62
    The extended (dectest.zip) and subset (dectest0.zip) testcase files (containing more than 81,300 tests). These cover all the operations and conversions described in the specifications, and include tests for the decimal encodings.

The decimal arithmetic described here combines the requirements of bothfixed-point and floating-point arithmetic, giving the followingadvantages:

  • 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 they wish.

  • 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 acontext 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 simplifying programming.

  • 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 X3.274–1996 standard. The same arithmetic has been included in Java 5, throughJSR 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 theIEEE 754-2008 and theISO/IEC/IEEE 60559:2011 standards.


The links below provide background and related information.

Some of the links below may be 'broken' (that is, no longer correct, orinvalid). My current strategy is toleave these here because in most cases the original and/ormost recent version of the page can be found at the 'Wayback machine'atthe Internet Archive ‐just copy the URL to the search field there.


Please send any comments or corrections toMike Cowlishaw (mfc),mfc@speleotrove.com; see alsospeleotrove.com.
Parts of these decimal arithmetic pages are reproduced with permissionfrom IBM © Copyright 1997, 2008 by International Business MachinesCorporation.Copyright © Mike Cowlishaw 1981, 2015.

[8]ページ先頭

©2009-2026 Movatter.jp