[libcxx] r182421 - Fix a couple of bugs in linear_congruential_engine::seed. Regression test added.

Howard Hinnant hhinnant at apple.com
Tue May 21 14:05:12 PDT 2013


Author: hhinnant
Date: Tue May 21 16:05:12 2013
New Revision: 182421

URL: http://llvm.org/viewvc/llvm-project?rev=182421&view=rev
Log:
Fix a couple of bugs in linear_congruential_engine::seed.  Regression test added.

Modified:
    libcxx/trunk/include/random
    libcxx/trunk/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp

Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=182421&r1=182420&r2=182421&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Tue May 21 16:05:12 2013
@@ -1835,7 +1835,7 @@ public:
     // types
     typedef _UIntType result_type;
 
-private:
+//private:
     result_type __x_;
 
     static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
@@ -1880,7 +1880,7 @@ public:
         seed(_Sseq& __q)
             {__seed(__q, integral_constant<unsigned,
                 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
-                             :  (__m-1) / 0x100000000ull)>());}
+                             :  (__m > 0x100000000ull))>());}
 
     // generating functions
     _LIBCPP_INLINE_VISIBILITY
@@ -1969,7 +1969,7 @@ linear_congruential_engine<_UIntType, __
     uint32_t __ar[__k+3];
     __q.generate(__ar, __ar + __k + 3);
     result_type __s = static_cast<result_type>((__ar[3] +
-                                                (uint64_t)__ar[4] << 32) % __m);
+                                              ((uint64_t)__ar[4] << 32)) % __m);
     __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
 }
 

Modified: libcxx/trunk/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp?rev=182421&r1=182420&r2=182421&view=diff
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp (original)
+++ libcxx/trunk/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp Tue May 21 16:05:12 2013
@@ -28,4 +28,12 @@ int main()
         e1.seed(sseq);
         assert(e1 == e2);
     }
+    {
+        unsigned a[] = {3, 5, 7, 9, 11};
+        std::seed_seq sseq(a, a+5);
+        typedef std::linear_congruential_engine<unsigned long long, 1, 1, 0x200000001ULL> E;
+        E e1(4309005589);
+        E e2(sseq);
+        assert(e1 == e2);
+    }
 }





More information about the cfe-commits mailing list