public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/50509] New: incorrect code in std::seed_seq::generate
@ 2011-09-24 18:14 john.salmon at deshaw dot com
  2011-09-24 18:29 ` [Bug libstdc++/50509] [C++0x] " paolo.carlini at oracle dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: john.salmon at deshaw dot com @ 2011-09-24 18:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50509

             Bug #: 50509
           Summary: incorrect code in std::seed_seq::generate
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: john.salmon@deshaw.com


The implementation of std::seed_seq::generate contains two typos.  The code
uses '<<' where the standard in rand.util.seed_seq 26.5.7.1 paragraph 8 says:

   T(x) is defined as x xor (x rshift 27)

Here's a patch against the 4.6.1 tree:

 salmonj@drdlogin0039.en.desres$ diff -u 
/proj/desres/root/Linux/x86_64/gcc/4.6.1-23A/include/c++/4.6.1/bits/random.tcc
myrandom/bits/random.tcc
---
/proj/desres/root/Linux/x86_64/gcc/4.6.1-23A/include/c++/4.6.1/bits/random.tcc 
  2011-06-27 15:29:53.000000000 -0400
+++ myrandom/bits/random.tcc    2011-09-19 10:04:46.836512000 -0400
@@ -2768,7 +2768,7 @@
       _Type __arg = (__begin[__k % __n]
              ^ __begin[(__k + __p) % __n]
              ^ __begin[(__k - 1) % __n]);
-      _Type __r1 = __arg ^ (__arg << 27);
+      _Type __r1 = __arg ^ (__arg >> 27);
       __r1 = __detail::__mod<_Type, __detail::_Shift<_Type, 32>::__value,
                              1664525u, 0u>(__r1);
       _Type __r2 = __r1;
@@ -2790,7 +2790,7 @@
       _Type __arg = (__begin[__k % __n]
              + __begin[(__k + __p) % __n]
              + __begin[(__k - 1) % __n]);
-      _Type __r3 = __arg ^ (__arg << 27);
+      _Type __r3 = __arg ^ (__arg >> 27);
       __r3 = __detail::__mod<_Type, __detail::_Shift<_Type, 32>::__value,
                              1566083941u, 0u>(__r3);
       _Type __r4 = __r3 - __k % __n;
salmonj@drdlogin0039.en.desres$


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

end of thread, other threads:[~2011-09-24 18:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-24 18:14 [Bug libstdc++/50509] New: incorrect code in std::seed_seq::generate john.salmon at deshaw dot com
2011-09-24 18:29 ` [Bug libstdc++/50509] [C++0x] " paolo.carlini at oracle dot com
2011-09-24 18:30 ` paolo at gcc dot gnu.org
2011-09-24 19:06 ` paolo.carlini at oracle dot com
2011-09-24 20:31 ` paolo 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).