
Boost : 
Subject: Re: [boost] [serialization] How are floating point values handled?
From: John Maddock (john_at_[hidden])
Date: 20130808 12:22:04
> hmmm section 18.3.2.4 of the standards says:
>
> static constexpr int digits10;
> 11 Number of base 10 digits that can be represented without change.198
> 12 Meaningful for all specializations in which is_bounded != false.
>
> static constexpr int max_digits10;
> 13 Number of base 10 digits required to ensure that values which differ
> are always differentiated.
> 14 Meaningful for all floating point types.
>
> So I don't read this as number of digits to the right of the decimal
> point.
> I take it to be number of significant digits which is not the same to me.
> But maybe it is. In anycase it looks like I should be using max_digits10
> instead of digits10+2 in anycase.
max_digits10 is a C++11 feature, but there's a config macro for it
somewhere.
However, you're confusing "how many digits do I need to fully represent this
type", with "how do you want this type formatted". There are basically 3
formatting options:
1) std::ios_base::fixed is set. Then the precision is interpreted as the
number of digits after the decimal point.
2) std::ios_base::scientific is set. The precision is interpreted as the
number of significant digits to print.
3) Neither of the above are set (the default for a new stream). The
formatter chooses either (1) or (2) based on conditions I don't recall, but
basically large exponents go to (2).
If you care about being able to reread the value back in you have to choose
(2), the other options are for "pretty printing" for humans to read.
HTH, John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk