From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2999 invoked by alias); 4 Sep 2014 16:52:48 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 2908 invoked by uid 48); 4 Sep 2014 16:52:44 -0000 From: "schwan@uni-mainz.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/63176] New: std::generate_canonical::digits> generates 1.0 Date: Thu, 04 Sep 2014 16:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: schwan@uni-mainz.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg01071.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63176 Bug ID: 63176 Summary: std::generate_canonical::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 #include #include 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::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.