ABSTRACT
The real numbers are pervasive, both in daily life, and in mathematics. Students spend much time studying their properties. Yet computers and programming languages generally provide only an approximation geared towards performance, at the expense of many of the nice properties we were taught in high school.
Although this is entirely appropriate for many applications, particularly those that are sensitive to arithmetic performance in the usual sense, we argue that there are others where it is a poor choice. If arithmetic computations and result are directly exposed to human users who are not floating point experts, floating point approximations tend to be viewed as bugs. For applications such as calculators, spreadsheets, and various verification tasks, the cost of precision sacrifices is high, and the performance benefit is often not critical. We argue that previous attempts to provide accurate and understandable results for such applications using the recursive reals were great steps in the right direction, but they do not suffice. Comparing recursive reals diverges if they are equal. In many cases, comparison of numbers, including equal ones, is both important, particularly in simple cases, and intractable in the general case.
We propose an API for a real number type that explicitly provides decidable equality in the easy common cases, in which it is often unnatural not to. We describe a surprisingly compact and simple implementation in detail. The approach relies heavily on classical number theory results. We demonstrate the utility of such a facility in two applications: testing floating point functions, and to implement arithmetic in Google's Android calculator application.
- Oliver Aberth. 1974. A Precise Numerical Analysis Program. Commun. ACM 17, 9 (September 1974), 509–513.Google Scholar
Digital Library
- Oliver Aberth. 1988. Precise Numerical Analysis. Wm. C. Brown.Google Scholar
- annymous. 2014. Odd bug in calculator app. https://www.reddit.com/ r/Android/comments/2ph1wk/odd_bug_in_calculator_app/ 18 With occurrence frequency determined by e.g. what expressions users enter into a calculator. Towards an API for the Real Numbers PLDI ’20, June 15–20, 2020, London, UKGoogle Scholar
- ASKVG. 2012. Microsoft Windows Calculator Bug, Sqrt(4) – 2 != 0. https://www.askvg.com/microsoft-windows-calculator-bug/Google Scholar
- Alan Baker. 1990. Transcendental number theory, Cambridge Mathematical Library (2nd ed.). Cambridge University Press.Google Scholar
- Erret Bishop. 1967. Foundations of Constructive Real Analysis. McGraw-Hill.Google Scholar
- Erret Bishop and Douglas Bridges. 1985. Constructive Analysis. Springer-Verlag.Google Scholar
- Jens Blanck. 2000. Exact Real Arithmetic Systems: Results of Competition. In Proceedings of the Workshop on Computability and Complexity in Analysis, Springer LNCS 2064. 389–393.Google Scholar
- Hans-J. Boehm. 2019. Floating point precision test. https://androidreview.googlesource.com/c/platform/art/+/1012109Google Scholar
- Hans-J. Boehm. 1987. Constructive Real Interpretation of Numerical Programs. In Proceedings of the SIGPLAN ’87 Symposium on Interpreters and Interpretive Techniques. 214–221.Google Scholar
Digital Library
- Hans-J. Boehm. 2005. The constructive reals as a Java library. J. Logic and Algebraic Programming 64 (2005), 3––11. Issue 1.Google Scholar
Cross Ref
- Hans-J. Boehm. 2017. Small-Data Computing: Correct Calculator Arithmetic. Commun. ACM 60, 8 (July 2017), 44–49. 10.1145/2911981 Google Scholar
Digital Library
- Hans-J. Boehm, Robert Cartwright, Michael J. O’Donnell, and Mark Riggle. 1986. Exact Real Arithmetic: A Case Study in Higher Order Programming. In Proceedings of the 1986 ACM Conference on Lisp and Functional Programming. 162–173.Google Scholar
Digital Library
- Keith Briggs. 2006. Implementing Exact Real Arithmetic in Python, C++ and C. Theor. Comput. Sci. 351, 1 (Feb. 2006), 74–81. Google Scholar
Digital Library
- Raymond Chen. 2016. Why does the Windows calculator generate tiny errors when calculating the square root of a perfect square? https://devblogs.microsoft.com/oldnewthing/?p=93765Google Scholar
- M Coste and M. F. Roy. 1988. Thom’s Lemma, the Coding of Real Algebraic Numbers and the Computation of the Topology of Semialgebraic Sets. Journal of Symbolic Computation 5 (1988), 121–129.Google Scholar
Digital Library
- Sicun Gao, Jeremy Avigad, and Edmund M. Clarke. 2012. Delta-Decidability over the Reals. In Proceedings of the 27th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS ’12). IEEE Computer Society Press, 305–314.Google Scholar
- David Goldberg. 1991. What Every Computer Scientist Should Know About Floating-point Arithmetic. ACM Comput. Surv. 23, 1 (March 1991), 5–48. Google Scholar
Digital Library
- Google Play. 2020. Google Calculator Reviews. https://play.google.com/store/apps/details?id=com.google.android. calculator&showAllReviews=trueGoogle Scholar
- James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Alex Buckley, and Daniel Smith. 2008.Google Scholar
- The Java Language Specification: Java SE 11 Edition. Oracle.Google Scholar
- Paul Gowland and David Lester. 2000. A Survey of Exact Arithmetic Implementations. In Proceedings of the Workshop on Computability and Complexity in Analysis, Springer LNCS 2064. 30–47.Google Scholar
- John L. Gustafson and Isaac T. Yonemoto. 2017. Beating floating point at its own game: Posit arithmetic. Supercomputing Frontiers and Innovations 4, 2 (2017), 71–86.Google Scholar
Digital Library
- M. Haselman, M. Beauchamp, A. Wood, S. Hauck, K. Underwood, and K.S. Hemmert. 2005. A comparison of floating point and logarithmic number systems for FPGAs. In 13th Annual IEEE Symposium on Field-Programmable Custom Computing Machines (FCCM’05). 181–190.Google Scholar
- IEEE CS. 2008. 754-2008 - IEEE Standard for Floating-Point Arithmetic.Google Scholar
- M. Laczkovich. 2003. The removal of π from some undecidable problems involving elementary functions. Proc. Amer. Math. Soc. 131, 7 (2003), 2235?2240.Google Scholar
- Vernon Lee and Hans-J. Boehm. 1990. Optimizing Programs over the Constructive Reals. In Proceedings of the SIGPLAN 1990 Conference on Programming Language Design and Implementation. 102–111.Google Scholar
Digital Library
- Valérie Ménissier-Morain. 1994. Arithmétique exacte, conception, algorithmique et performances d’une implémentation informatique en précision arbitraire. Thèse. Université Paris 7.Google Scholar
- David Monniaux. 2008. The Pitfalls of Verifying Floating-point Computations. ACM Trans. Program. Lang. Syst. 30, 3, Article 12 (May 2008), 41 pages. Google Scholar
Digital Library
- Norbert Th. Mueller. 2000. The iRRAM: Exact Real Arithmetic in C++. In Proceedings of the Workshop on Computability and Complexity in Analysis, Springer LNCS 2064. 222–252.Google Scholar
- Pavel Panchekha, Alex Sanchez-Stern, James R. Wilcox, and Zachary Tatlock. 2015. Automatically Improving Accuracy for Floating Point Expressions. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation (Portland, OR, USA) (PLDI ’15). ACM, New York, NY, USA, 1–11. 2737924.2737959 Google Scholar
Digital Library
- Dan Richardson and John Fitch. 1994. The Idenitity Problem for Elementary Functions and Constants. In ISSAC ’94 Proceedings of the international symposium on Symbolic and algebraic computation. 285– 290.Google Scholar
- Alex Sanchez-Stern, Pavel Panchekha, Sorin Lerner, and Zachary Tatlock. 2018. Finding Root Causes of Floating Point Error. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (Philadelphia, PA, USA) (PLDI 2018). ACM, New York, NY, USA, 256–269. Google Scholar
Digital Library
- Stephen Shankland. 2008. Google’s calculator muffs some math problems. https://www.cnet.com/news/googles-calculator-muffs-somemath-problemsGoogle Scholar
- Benjamin Sherman, Jesse Michael, and Michael Carbin. 2019. Sound and Robust Solid Modeling via Exact Real Arithmetic and Continuity. Proceedings, ACM Program. Lang., ICFP 3, Article 99 (8 2019), 29 pages. Google Scholar
Digital Library
- Benjamin Sherman, Luke Sciarappa, Adam Chlipala, and Michael Carbin. 2018. Computable Decision Making on the Reals and Other Spaces: Via Partiality and Nondeterminism. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (Oxford, United Kingdom) (LICS ’18). ACM, New York, NY, USA, 859–868. Google Scholar
Digital Library
- A. K. Simpson. 1998. Lazy functional algorithms for Exact Real Functionals. In Mathematical Foundations of Computer Science, Springer LNCS 1450. 456–464.Google Scholar
- Jean Vuillemin. 1990. Exact Real Arithmetic with Continued Fractions. IEEE Trans. Comput. 39, 8 (1990), 1087–1105.Google Scholar
Digital Library
- K. Weirauch and C. Kreitz. 1987. Representations of the Real Numbers and of the open subsets of the real numbers. Annals of Pure and Applied Logic 35, 3 (1987), 247–260.Google Scholar
Cross Ref
Index Terms
Towards an API for the real numbers
Recommendations
Error estimates for the summation of real numbers with application to floating-point summation
AbstractStandard Wilkinson-type error estimates of floating-point algorithms involve a factor $$\gamma _k:=k\mathbf {u}/(1-k\mathbf {u})$$ for $$\mathbf {u}$$ denoting the relative rounding error unit of a floating-point number system. Recently, it was ...
A study of decimal left shifters for binary numbers
The importance of decimal floating-point (DFP) arithmetic has been growing in the last years, and specifications for it are included in the revised IEEE 754 Standard for Floating-Point Arithmetic (IEEE 754-2008). IEEE 754-2008 specifies a binary ...
Towards a Quaternion Complex Logarithmic Number System
The well-known generalization of real to complex arithmetic (two reals) extends further to more obscure quaternion arithmetic (four reals), which has applications in signal processing, aerospace, graphics and virtual reality. Quaternion multiplication ...






Comments