Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2024-01-26 21:03:30


pt., 26 sty 2024 o 11:48 Matt Borland <matt_at_[hidden]> napisał(a):

>
>
> 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.
>
> 1.
>
>
> I believe that answers the question, but please let me know if it does not.
>

That's exactly what I was after. Thank you.

&rzej;

>
> Matt
>
>
>


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