Thursday, Feb 4, 2021 [Tweets] [Favorites]

SwiftDtoa v2

tbkka (via Steve Canon):

SwiftDtoa is the C/C++ code used in the Swift runtime to produce the textual representations used by the description and debugDescription properties of the standard Swift floating-point types. This update includes a number of algorithmic improvements to SwiftDtoa to improve portability, reduce code size, and improve performance but does not change the actual output.

[…]

Parsing the decimal form will yield exactly the same binary floating-point value again.

[…]

Among all accurate forms, this form has the fewest significant digits.

[…]

Algorithms that can produce this “optimal” output have been known since at least 1990, when Steele and White published their Dragon4 algorithm. However, Dragon4 and other algorithms from that period relied on high-precision integer arithmetic, which made them slow. More recently, a surge of interest in this problem has produced dramatically better algorithms that can produce the same results using only fast fixed-precision arithmetic.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment