A blog by Chad Nauseam has sparked interest in the difficulty of creating a simple calculator, showing that the iOS calculator fails to give the right answer to a sum, while Android’s counterpart gives the correct result.
The post explores the history of calculators and the issue of floating-point numbers, which have a finite precision, leading to errors when performing operations that combine large and small numbers.
The post then explores the work of Google developer Hans-J. Boehm, who used recursive real arithmetic (RRA) to overcome the issue.
However, this solution means there is no way to differentiate between very small numbers and zero, so an accurate result for “1-1” could be “0.000000000”, which is correct but potentially upsetting due to the excess precision.
The key conclusion was that RRA could be used for cases dealing with inexact numbers, using rationals most of the time, and switching to RRA for the approximation when dealing with potentially irrational results.