General Decimal Arithmetic 浮点算法
General Decimal Arithmetic http://speleotrove.com/decimal/
| General Decimal Arithmetic [ FAQ | Decimal web links | Bibliography | Arithmetic specification | Formats (encodings) | decNumber C implementation | DFPAL | Testcases | Summary | Web links | Densely Packed Decimal | Speleotrove | Contact ] |
![]() |
| 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 implementation. 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 IEEE 754 standard (‘754-2008’) published by the IEEE in August 2008, and the ISO/IEC/IEEE 60559:2011 standard, published by ISO in July 2011. IEEE 754-2008 is currently undergoing a minor revision.
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 IBM POWER6 and POWER7 processors, the firmware (with assists) in the IBM System z9 mainframe, and the hardware decimal floating-point unit in the IBM System z10 and later mainframe processors (see this paper for details)
- SilMinds’ Decimal Floating Point Arithmetic hardware IP Cores Family (see also their presentation for some details)
- Fujitsu’s decimal instructions in the SPARC64 X processor (see presentation, charts 5 & 6).
- GCC 4.2 and later includes support for most of the ISO C extensions (ISO/IEC TS 18661-2) for decimal floating point.
For more information and details of later GCC versions, etc., see Nelson H.F.Beebe's Decimal-arithmetic support in gcc compilers page. - SAP NetWeaver 7.1, which includes the new DECFLOAT datatype in ABAP, with support for hardware decimal floating-point on Power6
- IBM XL C/C++ for AIX, Linux and z/OS, DB2 for z/OS, Linux, UNIX, and Windows, and Enterprise 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
Stefan Krah’s mpdecimal package (libmpdec): a complete implementation of the General Decimal Arithmetic Specification that will – with minor restrictions – also conform to the IEEE 754-2008 Standard for Floating-Point Arithmetic. Starting from Python-3.3, libmpdec is the basis for Python's decimal module.
The combination of formats and arithmetic defined here and in the IEEE 754 and ISO/IEC/IEEE 60559:2011 standards 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 and easily.
The main features of the arithmetic are summarized below. 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).
Parts of these decimal arithmetic pages are reproduced with permission from IBM © Copyright 1997, 2008 by International Business Machines Corporation. Copyright © Mike Cowlishaw 1981, 2015.
Documentation and downloads
Here you will find documentation and downloads for decimal arithmetic, fixed-size decimal formats (encodings) and their performance, 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:
Arithmetic Version Description Specification
[.html | .pdf]1.70
2009.03.25Decimal 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.
Formats Version Description Specification
[.html | .pdf]1.01
2009.03.20Concrete 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
2009.03.21Performance measurements on three implementations that support the IEEE 754 decimal formats. Sample code
[.html]1.00
2003.04.10Java[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 PDF form. See also: A Decimal Floating-Point Specification, Schwarz et al., 15th IEEE Symposium on Computer Arithmetic [presentation charts].) - 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 datatypes.
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.
decNumber Version Description Documentation
[.html | .pdf]3.68
2010.01.23Describes 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.)Errata Known bugs and fixes since 3.56, 2007.10.12. 
International Components for Unicode (ICU)
decNumber package3.68
2010.02.10The 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 here.)GPL open source
decNumber C code
decExamples.zip3.53
2007.09.07‘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 below. - 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.
DFPAL Version Description Documentation
[.html | as .zip]2.20
2008.01.03The DFPAL User’s guide with overview, examples, compilation instructions, FAQ, etc. Download
DFPAL.zip
DFPAL.tar.gz2.20
2008.01.03The DFPAL source code (.h and .c files), together with the examples, the International Components for Unicode (ICU) license, the documentation in HTML format, etc. - Finally, the following language-independent testcases can be used for testing implementations:
Testcases Version Description Documentation
[.html | .pdf]2.44
2009.03.24Describes the testcase file format, testcase coverage, and testcase sources. Download
dectest.zip
dectest0.zip2.62
2010.04.19The 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. See also the IBM Haifa test suite (FPGen), and Hossam Fahmy’s Arithmetic 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 advantages:
|
|
Web links
The links below provide background and related information.
Background & Rationale
Hardware implementations
Software with hardware support
Software implementations
Partial/subset Implementations
Standards and Specifications
|
Bibliography
Related Decimal Links
Floating-point starter links
Multi-precision floating-point
Conversions
History Links
... and finally ... |
| Please send any comments or corrections to Mike Cowlishaw (mfc), mfc@speleotrove.com; see also speleotrove.com. |
| Parts of these decimal arithmetic pages are reproduced with permission from IBM © Copyright 1997, 2008 by International Business Machines Corporation. Copyright © Mike Cowlishaw 1981, 2015. Java is a trademark of Sun Microsystems Inc. and Oracle. |
General Decimal Arithmetic 浮点算法的更多相关文章
- Python 的上下文管理器是怎么设计的?
花下猫语:最近,我在看 Python 3.10 版本的更新内容时,发现有一个关于上下文管理器的小更新,然后,突然发现上下文管理器的设计 PEP 竟然还没人翻译过!于是,我断断续续花了两周时间,终于把这 ...
- Lua的各种资源1
Libraries And Bindings LuaDirectory > LuaAddons > LibrariesAndBindings This is a list of l ...
- C语言qsort函数算法性能测试
对于该算法的复杂性.一个直接的方法是测量的一定量的算法级数据的执行时间的感知. 随着C语言提供qsort对于示例.随着100一万次的数据,以测试其计算量.感知O(nlg(n))时间成本: C码如下面: ...
- 图像相似度中的Hash算法
度量两张图片的相似度有许多算法,本文讲介绍工程领域中最常用的图片相似度算法之一--Hash算法.Hash算法准确的说有三种,分别为平均哈希算法(aHash).感知哈希算法你(pHash) ...
- 图像的相似度Hash算法
Hash算法有三种,分别为平均哈希算法(aHash).感知哈希算法你(pHash)和差异哈哈希算法(dHash). 针对以上三种的Hash算法详解见博客园文章 https://www.cnblogs. ...
- Maple拥有优秀的符号计算和数值计算能力
https://www.maplesoft.com/products/maple/ Maple高级应用和经典实例: https://wenku.baidu.com/view/f246962107221 ...
- C# Language Specification 5.0 (翻译)第四章 类型
C# 语言的类型分为两大类:值类型(value type)和引用类型(reference type),而它们又都同时具有至少一个类型形参的泛型类型(generic type).类型形参(type pa ...
- dD Geometry Kernel ( Geometry Kernels) CGAL 4.13 -User Manual
1 Introduction This part of the reference manual covers the higher-dimensional kernel. The kernel co ...
- 2D and 3D Linear Geometry Kernel ( Geometry Kernels) CGAL 4.13 -User Manual
1 Introduction CGAL, the Computational Geometry Algorithms Library, is written in C++ and consists o ...
随机推荐
- Windows外壳名字空间的浏览
Windows95/98对Dos/Win3.x作了许多重大改进,在文件系统方面,它除了采用长文件名替代Dos中的8.3文件名以外,引入外壳名字空间(Shell Name Space)来代Dos文件系统 ...
- ImageLoader使用
最近琢磨的网上的这些开源框架,imageLoader确实很好用,基本用法不记录了,参考网上的一些代码写了个ImageLoaderManager /** * Created by Lee on 2016 ...
- linux查找yum和rpm安装路径
linux查找yum和rpm安装路径 转:https://jingyan.baidu.com/article/86112f1378bf282737978730.html
- Atitit.wrmi web rmi框架新特性
Atitit.wrmi web rmi框架新特性 1. V1d 新特性1 1.1. 增加了精确参数1 1.2. 增加了req参数,命名参数模式..1 1.3. 增加了globale 传递隐含参数r ...
- Atitit.软件开发的非功能性需求attilax 总结At
Atitit.软件开发的非功能性需求attilax 总结 1. 运行环境约束:用户对软件系统运行环境的要求. 1 2. 兼容性 2 3. 7.6 数据库 database (imp by ati) ...
- python语言 buffer类型数据的使用 'ascii' codec can't decode byte 0xe5 问题的解决
在python中我们使用buffer类型时可以将其转换为str类型. 如果obejct的类型为<type 'buffer'> ,可以使用str(object)将其转换为字符串类型. 在转换 ...
- 基于AFNetworking封装的网络请求工具类【原创】
今天给大家共享一个我自己封装的网络请求类,希望能帮助到大家. 前提,导入AFNetworking框架, 关于修改AFN源码:通常序列化时做对text/plan等的支持时,可以一劳永逸的修改源代码,在a ...
- ubuntu如何使用minicom
minicom是linux下串口通信的软件,它的使用完全依靠键盘的操作,虽然没有“超级终端”那么易用,但是使用习惯之后读者将会体会到它的高效与便利,下面将讲解minicom的安装和配置. 一.安装mi ...
- Redis遍历所有key的两个命令 -- KEYS 和 SCAN
当我们需要遍历Redis所有key或者指定模式的key时,首先想到的是KEYS命令: KEYS pattern 官网对于KEYS命令有一个提示: KEYS 的速度非常快,例如,Redis在一个有1 ...
- php 常面试
问题:请用最简单的语言告诉我PHP是什么? 回答:PHP全称:Hypertext Preprocessor,是一种用来开发动态网站的服务器脚本语言. 问题:什么是MVC? 回答:MVC由Model(模 ...
