1. 10
  1.  

  2. 1

    I find this both cool and depressing. Cool because it works, depressing because serialising a binary floating point value as a decimal string is an inherently lossy process and it makes me sad that anyone is doing this enough that they care about performance: if you’re parsing floating point values from string representations for anything other than configuration files, you may have made some poor life choices.

    1. 1

      It’s not inherently lossy. There is a definition with proof and implementation here:

      https://dl.acm.org/doi/10.1145/3360595

      https://github.com/ulfjack/ryu

      Ryu generates the shortest decimal representation of a floating point number that maintains round-trip safety. That is, a correct parser can recover the exact original number. For example, consider the binary 32-bit floating point number 00111110100110011001100110011010. The stored value is exactly 0.300000011920928955078125. However, this floating point number is also the closest number to the decimal number 0.3, so that is what Ryu outputs.


      As for use cases, how do you get numbers into Excel without serializing to text? What about MS SQL server (honest question)? Text is the lowest common denominator.