Algorithm to convert an IEEE 754 double to a string?

前端 未结 4 1916
忘了有多久
忘了有多久 2020-11-27 05:48

Many programming languages that use IEEE 754 doubles provide a library function to convert those doubles to strings. For example, C has sprintf, C++ has

4条回答
  •  清酒与你
    2020-11-27 06:33

    See Ryan Juckett's Printing Floating-Point Numbers (2014), which describes history and implementations of floating-point to string conversions. In this four-part post, Ryan also provides a C++ implementation of Dragon4 based on Steele and White (1990), which is an efficient algorithm to convert a binary number in floating point format to a decimal number in string format.

    You can also see a C implementation of Ryan's Dragon4 for Numpy here, and use it within Python/Numpy 1.14 format_float_positional and format_float_scientific functions.


    In 2018, an algorithm/library Ryu was published, with bindings in many modern programming languages (C, Java, C++, C#, Scala, Rust, Julia, Go, ...)

提交回复
热议问题