public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0
@ 2014-09-04 16:52 schwan@uni-mainz.de
  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
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: schwan@uni-mainz.de @ 2014-09-04 16:52 UTC (permalink / raw)
  To: gcc-bugs

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.


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

* [Bug libstdc++/63176] std::generate_canonical<float, std::numeric_limits<float>::digits>() generates 1.0f
  2014-09-04 16:52 [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0 schwan@uni-mainz.de
@ 2015-08-26 21:28 ` redi at gcc dot gnu.org
  2015-08-26 21:28 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-08-26 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |6.0

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk.


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

* [Bug libstdc++/63176] std::generate_canonical<float, std::numeric_limits<float>::digits>() generates 1.0f
  2014-09-04 16:52 [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0 schwan@uni-mainz.de
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-08-26 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Wed Aug 26 21:27:09 2015
New Revision: 227233

URL: https://gcc.gnu.org/viewcvs?rev=227233&root=gcc&view=rev
Log:
Ensure std::generate_canonical doesn't return 1.

2015-08-26  Edward Smith-Rowland  <3dw4rd@verizon.net>
            Jonathan Wakely  <jwakely@redhat.com>

        PR libstdc++/64351
        PR libstdc++/63176
        * include/bits/random.tcc (generate_canonical): Loop until we get a
        result less than one.
        * testsuite/26_numerics/random/uniform_real_distribution/operators/
        64351.cc: New.

Added:
   
trunk/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/random.tcc


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

* [Bug libstdc++/63176] std::generate_canonical<float, std::numeric_limits<float>::digits>() generates 1.0f
  2014-09-04 16:52 [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0 schwan@uni-mainz.de
  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
  4 siblings, 0 replies; 6+ messages in thread
From: rs2740 at gmail dot com @ 2015-10-10  3:45 UTC (permalink / raw)
  To: gcc-bugs

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

TC <rs2740 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rs2740 at gmail dot com

--- Comment #3 from TC <rs2740 at gmail dot com> ---
This breaks the complexity requirement in [rand.util.canonical]/p3, though.


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

* [Bug libstdc++/63176] std::generate_canonical<float, std::numeric_limits<float>::digits>() generates 1.0f
  2014-09-04 16:52 [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0 schwan@uni-mainz.de
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-12 10:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Meh. Don't use generate_canonical<float> then.


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

* [Bug libstdc++/63176] std::generate_canonical<float, std::numeric_limits<float>::digits>() generates 1.0f
  2014-09-04 16:52 [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0 schwan@uni-mainz.de
                   ` (3 preceding siblings ...)
  2015-10-12 10:28 ` redi at gcc dot gnu.org
@ 2020-12-10 10:22 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-10 10:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to TC from comment #3)
> This breaks the complexity requirement in [rand.util.canonical]/p3, though.

That did get fixed eventually, see PR 80137 / r246542

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

end of thread, other threads:[~2020-12-10 10:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04 16:52 [Bug libstdc++/63176] New: std::generate_canonical<float, std::numeric_limits<float>::digits> generates 1.0 schwan@uni-mainz.de
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

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).