skip to main content
10.1145/1806596.1806623acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article

Printing floating-point numbers quickly and accurately with integers

Published:05 June 2010Publication History

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.

References

  1. R. G. Burger and R. K. Dybvig. Printing Floating-Point Numbers Quickly and Accurately. In Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, PLDI 1996, pages 108--116, New York, NY, USA, June 1996. ACM. doi: 10.1145/249069.231397. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. J. T. Coonen. An implementation guide to a proposed standard for floating-point arithmetic. Computer, 13(1): 68--79, 1980. ISSN: 0018--9162. doi: 10.1109/MC.1980.1653344. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. D. M. Gay. Correctly rounded binary-decimal and decimal-binary conversions. Technical Report 90--10, AT&T Bell Laboraties, Murray Hill, NJ, USA, Nov. 1990.Google ScholarGoogle Scholar
  4. D. Goldberg. What every computer scientist should know about floating-point arithmetic. ACM Computing Surveys, 23(1): 5--48, 1991. ISSN: 0360-0300. doi: 10.1145/103162.103163. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. D. E. Knuth. The Art of Computer Programming, Volume II: Seminumerical Algorithms, 2nd Edition. Addison-Wesley, 1981. ISBN: 0-201-03822-6.Google ScholarGoogle Scholar
  6. I. T. P754. ANSI/IEEE 754-1985, Standard for Binary Floating-Point Arithmetic. IEEE, New York, Aug. 12 1985.Google ScholarGoogle Scholar
  7. G. L. Steele Jr. and J. L. White. How to print floating-point numbers accurately. In Proceedings of the ACM SIGPLAN 1994 Conference on Programming Language Design and Implementation, PLDI 1994, pages 112--126, New York, NY, USA, 1990. ACM. ISBN: 0-89791-364-7. doi: 10.1145/93542.93559. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Printing floating-point numbers quickly and accurately with integers

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in
      • Published in

        cover image ACM Conferences
        PLDI '10: Proceedings of the 31st ACM SIGPLAN Conference on Programming Language Design and Implementation
        June 2010
        514 pages
        ISBN:9781450300193
        DOI:10.1145/1806596
        • cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 45, Issue 6
          PLDI '10
          June 2010
          496 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/1809028
          Issue’s Table of Contents

        Copyright © 2010 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 5 June 2010

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate406of2,067submissions,20%

        Upcoming Conference

        PLDI '24

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader