Hacker’s Multiple-Precision Integer-Division Program in Close Scrutiny

  • Jyrki KatajainenEmail author
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11544)


Before the era of ubiquitous computers, the long-division method was presented in primary schools as a paper-and-pencil technique to do whole-number division. In the book “Hacker’s Delight” by Warren [2nd edition, 2013], an implementation of this algorithm was given using the C programming language. In this paper we will report our experiences when converting this program to a generic program-library routine.

The highlights of the paper are as follows: (1) We describe the long-division algorithm—this is done for educational purposes. (2) We outline its implementation—the goal is to show how to use modern C++ to achieve flexibility, portability, and efficiency. (3) We analyse its computational complexity by paying attention to how the digit width affects the running time. (4) We compare the practical performance of the library routine against Warren’s original. It is pleasure to announce that the library routine is faster. (5) We release the developed routine as part of a software package that provides fixed-width integers of arbitrary length, e.g. a number of type Open image in new window (editor’s note: the non-transliterated form used in the code is Open image in new window ) has 2019 bits and it supports the same operations with the same semantics as a number of type Open image in new window .


Software library Multiple-precision arithmetic Algorithm Long division Description Implementation Meticulous analysis Experimentation 


  1. 1.
    Brinch Hansen, P.: Multiple-length division revisited: a tour of the minefield. Report 9-1992, Syracuse University (1992).
  2. 2.
    Collins, G.E., Musser, D.R.: Analysis of the Pope-Stein division algorithm. Inf. Process. Lett. 6(5), 151–155 (1977). Scholar
  3. 3.
    Gamby, A.N., Katajainen, J.: Convex-hull algorithms: implementation, testing, and experimentation. Algorithms 11(12) (2018). Scholar
  4. 4.
    Katajainen, J.: Pure compile-time functions and classes in the CPH MPL. CPH STL report 2017-2, Department of Computer Science, University of Copenhagen (2017).
  5. 5.
    Katajainen, J.: Class templates cphstl::\(\mathbb{N}\) and cphstl::\(\mathbb{Z}\) for fixed-precision arithmetic. Work in progress (2017–2019)Google Scholar
  6. 6.
    Knuth, D.E.: Seminumerical Algorithms, The Art of Computer Programming, vol. 2, 3rd edn. Addison Wesley Longman, Boston (1998)zbMATHGoogle Scholar
  7. 7.
    Krishnamurthy, E.V., Nandi, S.K.: On the normalization requirement of divisor in divide-and-correct methods. Commun. ACM 10(12), 809–813 (1967). Scholar
  8. 8.
    Lay-Yong, L.: On the Chinese origin of the galley method of arithmetical division. Br. J. Hist. Sci. 3(1), 66–69 (1966). Scholar
  9. 9.
    Mifsud, C.J.: A multiple-precision division algorithm. Commun. ACM 13(11), 666–668 (1970). Scholar
  10. 10.
    Mifsud, C.J., Bohlen, M.J.: Addendum to a multiple-precision division algorithm. Commun. ACM 16(10), 628 (1973). Scholar
  11. 11.
    Pope, D.A., Stein, M.L.: Multiple precision arithmetic. Commun. ACM 3(12), 652–654 (1960). Scholar
  12. 12.
    Warren Jr., H.S.: Hacker’s Delight, 2nd edn. Pearson Education Inc., London (2013)Google Scholar
  13. 13.
    Yong, L.L.: The development of Hindu-Arabic and traditional Chinese arithmetic. Chin. Sci. 13, 35–54 (1996). Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.Department of Computer ScienceUniversity of CopenhagenCopenhagen EastDenmark
  2. 2.Jyrki Katajainen and CompanyHundestedDenmark

Personalised recommendations