Quote:
> According to the ANSI standard precision is the number of
> digits after the decimal point.
Wrong. ostream::operator<<() for floating point numbers defers to
num_put locale facet. C++ standard 22.2.2.2.2 defines num_put::do_put in
terms of printf and specifies how a printf conversion specifier is
determined by ios_base flags. Fixed format becomes %f, scientific
becomes %e, and general format (the default) becomes %g. Precision is
added to the specifier. ios_base::showpos is represented by + modifier.
So, in your case with showpos and precision, say, 6, the format becomes
%+.6g in general format and %+.6f in fixed format.
Now, C++ standard does not define the behavior of printf, but instead
defers to C standard. C99 7.19.6.1/4 says:
An optional precision that gives ... the number of digits to appear
after the decimal-point character for a, A, e, E, f, and F conversions,
the maximum number of significant digits for the g and G conversions ...
Note how the meaning of precision field differs between %f and %g.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken