libstdc++/8135: fixed and scientfic output with different precisions is inconsistent with standard

paolo@gcc.gnu.org paolo@gcc.gnu.org
Thu Oct 3 13:52:00 GMT 2002


Synopsis: fixed and scientfic output with different precisions is inconsistent with standard

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Thu Oct  3 13:52:51 2002
Responsible-Changed-Why:
    Analyzed.
State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Thu Oct  3 13:52:51 2002
State-Changed-Why:
    Not a bug. Try the following, which compares libstdc++-v3
    to the letter of the standard (22.2.2.2.2,8 and 11)
    
    
    #include <iostream>
    #include <iomanip>
    #include <cstdio>
    
    using namespace std;
    
    const double pi = 3.1415926535,
                 sm = 0.00004321;
    
    void experiment();
    
    int main()
    {
        experiment();
        cout.setf(ios::fixed | ios::scientific, ios::floatfield);
        experiment();
    
        return 0;
    }
    
    void experiment()
    {
        cout << "floatfield:";
        ios::fmtflags f = cout.flags();
    
        if (f & ios::fixed)
            cout << " fixed";
        if (f & ios::scientific)
            cout << " scientific";
    
        cout << endl;
    
        for (int x = 0; x < 10; x++)
          {
            cout << x << ". " << setprecision(x)
                 << setw(20) << pi
                 << setw(20) << sm;
    	if (x > 0 || (cout.flags() & ios::fixed))
    	  printf("%20.*g%20.*g\n", x, pi, x, sm);
    	else
    	  printf("%20g%20g\n", pi, sm);
          }
    }

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8135



More information about the Gcc-bugs mailing list