Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2024-01-26 10:15:24


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

> >
>
> > > Are there some requirements on how the numbers are converted to
> > > characters? How is it that 1.03 is rendered as "1.03" when there are
> surely
> > > longer sequences of characters that are closer to the numeric value
> really
> > > stored in the object of type `double`.
> >
>
> >
>
> > If we treated the requirement to represent the printed number as
> accurately
> > as possible, then surely "1.029999998" would be a closer approximation of
> > the value being stored, no?
> >
>
>
> If the number can not be exactly represented tie-breaking is done by
> rounding to the nearest number with even significand. For example
> 9000000000000000.5 has the nearest two floating point values of
> 9000000000000000, or 9000000000000001 so we pick the former since it is
> even. See page 2: https://arxiv.org/pdf/2101.11408.pdf.
>

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
clevernes 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;

>
> Matt


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