public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "schwan@uni-mainz.de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0
Date: Thu, 04 Sep 2014 16:52:00 -0000	[thread overview]
Message-ID: <bug-63176-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63176

            Bug ID: 63176
           Summary: std::generate_canonical<float,
                    std::numeric_limits<float>::digits> generates 1.0
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: schwan@uni-mainz.de

std::generate_canonical can generate 1.0, which does not conform to the c++11
standard. On my box the following program yields "Bug!":

#include <iostream>
#include <limits>
#include <random>

int main()
{
    std::mt19937 rng;

    std::seed_seq sequence{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    rng.seed(sequence);
    rng.discard(12 * 629143 + 6);

    float random = std::generate_canonical<float,
                   std::numeric_limits<float>::digits>(rng);

    if (random == 1.0f)
    {
        std::cout << "Bug!\n";
    }

    return 0;
}

See also
http://stackoverflow.com/questions/25668600/is-1-0-a-valid-random-number for a
longer discussion and analysis of the problem.

I first noticed this on my system GCC,

gcc (Gentoo 4.7.3-r1 p1.4, pie-0.5.5) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

but I can reproduce the same behavior with a recent GCC from git:

gcc (GCC) 5.0.0 20140830 (experimental)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I used `c++ =std=c++11` to compile the program above.


             reply	other threads:[~2014-09-04 16:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-04 16:52 schwan@uni-mainz.de [this message]
2015-08-26 21:28 ` [Bug libstdc++/63176] std::generate_canonical<float, std::numeric_limits<float>::digits>() generates 1.0f redi at gcc dot gnu.org
2015-08-26 21:28 ` redi at gcc dot gnu.org
2015-10-10  3:45 ` rs2740 at gmail dot com
2015-10-12 10:28 ` redi at gcc dot gnu.org
2020-12-10 10:22 ` redi at gcc dot gnu.org

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=bug-63176-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).