savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
155 stars 12 forks source link

Add `FloatingPoint.Format`, using the Ryū algorithm. #365

Closed jemc closed 1 year ago

jemc commented 1 year ago

The Ryū algorithm is a fast and accurate way to print floating-point numbers, using some clever bit magic and lookup tables.

At this time we implement only the 64-bit version of the algorithm, but in the future a 32-bit version could be implemented as well. But for now, when printing F32s we will first convert to F64.

Prior to this commit, we were relying on snprintf to print floating point numbers, which is slower and not as portable (it's not working on Windows without linking additional libraries).