Boost logo

Boost :

From: Matt Borland (matt_at_[hidden])
Date: 2024-01-26 07:30:14


>

> > 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.

Matt





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