Possible regression from gcc-3.0.x to gcc-3.2.x with std::setprecision
Andrew Pollard
andrewp@andypo.net
Fri Jan 3 06:26:00 GMT 2003
>>Indeed, and fixing it seems easy. But *why*?!?
>>
>>Why, that is, more than digits10 + 1 digits are necessary for min()?
>
>I think example code that demonstrates this issue should help with our
>confusion...
I've submitted a GNATS report. Example test case included in it.
libstdc++/9151: [3.2/3.3/3.4 regression] std::setprecision limited to
16 digits when outputting a double to a stream
I agree that 16 digits 'should' be sufficient, but it is interesting
that the gcc-3.0 code does indeed have the digits10+3 in it and not
digits10+1.
max() and numeric_limits<float>::min() and max() have the same
behaviour when used in the test program....
double.cxx:
--------------------
#include <limits>
#include <sstream>
#include <iomanip>
int
main()
{
int prec = std::numeric_limits<double>::digits10+3;
double val1 = std::numeric_limits<double>::min();
double val2 = 0.0;
std::stringstream ss1;
ss1 << std::setprecision(prec) << val1 << std::ends;
std::stringstream ss2(ss1.str());
ss2 >> val2;
return (val1 == val2);
}
----------------------
% gcc30 double.cxx; ./a.out; echo $?
1
% gcc32 double.cxx; ./a.out; echo $?
0
(Similarly for 3.3 and 3.4)
[ BTW, we only noticed this since we are doing XML marshalling of
types in our system, and we happened to have some internal tests
testing these numbers.... ]
Andrew.
--
Andrew Pollard, Brooks-PRI Automation | home: andrew@andypo.net
670 Eskdale Road, Winnersh Triangle, UK | work: Andrew.Pollard@brooks-pri.com
Tel/Fax:+44 (0)118 9215603 / 9215660 | http://www.andypo.net
More information about the Libstdc++
mailing list