diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2013-05-21 21:05:12 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2013-05-21 21:05:12 +0000 |
| commit | 849821cffb2fe404593450b7b067bee8704bcb4d (patch) | |
| tree | ea2aefe02f16dc79c1b5b1fcc5f3e855f90b4432 /libcxx | |
| parent | eaa153bdad8a789245d97a6c3bee261e0f795d2b (diff) | |
| download | bcm5719-llvm-849821cffb2fe404593450b7b067bee8704bcb4d.tar.gz bcm5719-llvm-849821cffb2fe404593450b7b067bee8704bcb4d.zip | |
Fix a couple of bugs in linear_congruential_engine::seed. Regression test added.
llvm-svn: 182421
Diffstat (limited to 'libcxx')
| -rw-r--r-- | libcxx/include/random | 6 | ||||
| -rw-r--r-- | libcxx/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/libcxx/include/random b/libcxx/include/random index 92722ea64e7..f1076f97302 100644 --- a/libcxx/include/random +++ b/libcxx/include/random @@ -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, __a, __c, __m>::__seed(_Sseq& __q, 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; } diff --git a/libcxx/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp b/libcxx/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp index 470726f7f31..ca2793c7f9a 100644 --- a/libcxx/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp +++ b/libcxx/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp @@ -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); + } } |

