public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: a.b.taylor@sympatico.ca
To: gcc-gnats@gcc.gnu.org
Cc: ledermg@mail.mohawkc.on.ca
Subject: libstdc++/8135: fixed and scientfic output with different precisions is inconsistent with standard
Date: Thu, 03 Oct 2002 12:36:00 -0000	[thread overview]
Message-ID: <20021003192619.10494.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-10-03 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-03 12:36 a.b.taylor [this message]
2002-10-03 13:52 paolo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021003192619.10494.qmail@sources.redhat.com \
    --to=a.b.taylor@sympatico.ca \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=ledermg@mail.mohawkc.on.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).