Boost logo

Boost :

From: Matt Borland (matt_at_[hidden])
Date: 2024-01-26 10:47:46


Thanks. But the document describes the parsing part, where you have to make the choice to select a value from a finite set. My question is more about serialization. I am pretty sure that the representation of seemingly simple numbers, like "10.2" is in reality ugly, and the output string has the capability to represent nearly everything, there needs to be some cleverness applied to control the balance between the accuracy, and producing a nice-to-human text as "10.2". My question is, does the specification of `std::to_chars` impose strict, unambiguous rules, or do you have the liberty to choose within some limit.

Does my question make sense?

Regards,
&rzej;

>From the standard for std::to_chars (22.13.2) you have to give the shortest representation (if no precision specified), and "If there are several such representations, the representation with the smallest difference from the floating-point argument value is chosen, resolving any remaining ties using rounding according to round_to_nearest". The behavior of round_to_nearest is defined in IEEE 754 which is also unambiguous. The algorithm used in boost::charconv::to_chars is described here: https://github.com/jk-jeon/dragonbox/blob/master/other_files/Dragonbox.pdf, and the basis code is in the same repository.

I believe that answers the question, but please let me know if it does not.

Matt






Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk