public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/8135: fixed and scientfic output with different precisions is inconsistent with standard
@ 2002-10-03 13:52 paolo
  0 siblings, 0 replies; 2+ messages in thread
From: paolo @ 2002-10-03 13:52 UTC (permalink / raw)
  To: a.b.taylor, gcc-bugs, gcc-prs, ledermg, nobody, paolo

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* libstdc++/8135: fixed and scientfic output with different precisions is inconsistent with standard
@ 2002-10-03 12:36 a.b.taylor
  0 siblings, 0 replies; 2+ messages in thread
From: a.b.taylor @ 2002-10-03 12:36 UTC (permalink / raw)
  To: gcc-gnats; +Cc: ledermg


>Number:         8135
>Category:       libstdc++
>Synopsis:       fixed and scientfic output with different precisions is inconsistent with standard
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 03 12:36:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Allen B. Taylor
>Release:        3.2
>Organization:
>Environment:
DJGPP: djdev203.zip, gcc32b.zip, gpp32d.zip, bnu213b.zip.
>Description:
The following program generates incorrect output for floating-point output when setting various values for floatfield flags (fixed and scientific) and precision. When fixed alone or scientific alone are set, the precision is interpreted correctly (number of digits to the right of the decimal point). When both fixed and scientific are not set (the default state of cout), precision is misinterpreted (see output). Similar, but not identical output results from having both fixed and scientific set at the same time. The standard states in section 22.2.2.2 para 8 (table 58)that if neither flag is set, or if both flags are set, then floating-point numbers should print according to printf specifier %g (or %G if uppercase is set), but I think something else is happening.
>How-To-Repeat:
#include <iostream>
#include <iomanip>

using namespace std;

const double pi = 3.1415926535,
             sm = 0.00004321;

void experiment();

int main()
{
    experiment();
    cout.setf(ios::fixed, ios::floatfield);
    experiment();
    cout.setf(ios::scientific, ios::floatfield);
    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
             << endl;
}
>Fix:
None.
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-03 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-03 13:52 libstdc++/8135: fixed and scientfic output with different precisions is inconsistent with standard paolo
  -- strict thread matches above, loose matches on Subject: below --
2002-10-03 12:36 a.b.taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).