Schubfach: The smallest double-to-string implementation
12 days ago
- #algorithm
- #C++
- #floating-point
- Schubfach algorithm converts binary floating-point numbers to shortest decimal representations with round-trip guarantees.
- It uses the pigeonhole principle to non-iteratively determine the correct decimal exponent.
- The algorithm replaces costly arbitrary-precision arithmetic with efficient fixed-precision integer arithmetic.
- Schubfach ensures accuracy by leveraging the Nadezhin result to avoid critical boundary issues.
- The rounding interval concept is central, ensuring any decimal within it rounds back to the original floating-point value.
- A minimal C++ implementation demonstrates the algorithm's efficiency and simplicity.
- Performance benchmarks show Schubfach is competitive with other leading algorithms like Ryu and Dragonbox.
- The implementation is available under MIT license, offering a practical solution for developers.