Double-double: 31 digits of precision without leaving the FPU
Floating-point numbers come in various formats, with a double offering around 15 decimal digits of precision for free. Arbitrary-precision libraries can provide as many digits as needed, but at a significant performance cost. Between the insufficient precision of a double and the high cost of arbitrary-precision libraries lies a middle ground that can be achieved by combining two doubles into a single value.
This method, known as double-double, provides roughly 31 decimal digits of precision while maintaining performance close to that of a plain double.
The double-double type stores the sum of two doubles without evaluating it, preserving the leading digits in one double and the remaining digits in another. This allows for error-free transformations and operations while maintaining nearly the same performance as a double. The algorithm used to maintain the invariant invariant that the high part carries the value, and the low part carries the error of the high part after addition, is based on Knuth's two-sum method.
While this technique offers significant advantages, it does have its limits. As numbers become increasingly large or small, the double-double type can no longer maintain its precision. However, for many applications requiring higher precision than a double can provide, the double-double method offers a practical and efficient solution.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.