Printing floating-point numbers: a faster, always correct method

Marc Andrysco, Ranjit Jhala, Sorin Lerner
2016
1 reference

Abstract

Floating-point numbers are an essential part of modern software, recently gaining particular prominence on the web as the exclusive numeric format of Javascript. To use floating-point numbers, we require a way to convert binary machine representations into human readable decimal outputs. Existing conversion algorithms make trade-offs between completeness and performance. The classic Dragon4 algorithm by Steele and White and its later refinements achieve completeness --- i.e. produce correct and optimal outputs on all inputs --- by using arbitrary precision integer (bignum) arithmetic which leads to a high performance cost. On the other hand, the recent Grisu3 algorithm by Loitsch shows how to recover performance by using native integer arithmetic but sacrifices optimality for 0.5% of all inputs. We present Errol, a new complete algorithm that is guaranteed to produce correct and optimal results for all inputs while simultaneously being 2x faster than the incomplete Grisu3 and 4x faster than previous complete methods.

1 repository
1 reference

Code References

swiftlang/swift
1 file
stdlib/public/core/FloatingPointToString.swift
1
/// https://doi.org/10.1145/2837614.2837654
Link copied to clipboard!