Affiliation:
1. Inria, Sophia Antipolis, France
Abstract
We present algorithms for accurately converting floating-point numbers to decimal representation. They are fast (up to 4 times faster than commonly used algorithms that use high-precision integers) and correct: any printed number will evaluate to the same number, when read again.
Our algorithms are fast, because they require only fixed-size integer arithmetic. The sole requirement for the integer type is that it has at least two more bits than the significand of the floating-point number. Hence, for IEEE 754 double-precision numbers (having a 53-bit significand) an integer type with 55 bits is sufficient. Moreover we show how to exploit additional bits to improve the generated output.
We present three algorithms with different properties: the first algorithm is the most basic one, and does not take advantage of any extra bits. It simply shows how to perform the binary-to-decimal transformation with the minimal number of bits. Our second algorithm improves on the first one by using the additional bits to produce a shorter (often the shortest) result.
Finally we propose a third version that can be used when the shortest output is a requirement. The last algorithm either produces optimal decimal representations (with respect to shortness and rounding) or rejects its input. For IEEE 754 double-precision numbers and 64-bit integers roughly 99.4% of all numbers can be processed efficiently. The remaining 0.6% are rejected and need to be printed by a slower complete algorithm.
Publisher
Association for Computing Machinery (ACM)
Subject
Computer Graphics and Computer-Aided Design,Software
Reference6 articles.
1. Printing floating-point numbers quickly and accurately
2. Special Feature an Implementation Guide to a Proposed Standard for Floating-Point Arithmetic
3. What every computer scientist should know about floating-point arithmetic
4. I. T. P754. ANSI/IEEE 754-1985 Standard for Binary Floating-Point Arithmetic. IEEE New York Aug. 12 1985. I. T. P754. ANSI/IEEE 754-1985 Standard for Binary Floating-Point Arithmetic. IEEE New York Aug. 12 1985.
Cited by
2 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. Infra: structure all the way down: structured data as a visual programming language;Proceedings of the 2017 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software;2017-10-25
2. Rethinking the human-readability infrastructure;Proceedings of the Workshop on Future Programming;2015-10-26