Fix a couple of bugs in linear_congruential_engine::seed. Regression test added.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@182421 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a71a952634
commit
8f72d5ce16
@ -1835,7 +1835,7 @@ public:
|
|||||||
// types
|
// types
|
||||||
typedef _UIntType result_type;
|
typedef _UIntType result_type;
|
||||||
|
|
||||||
private:
|
//private:
|
||||||
result_type __x_;
|
result_type __x_;
|
||||||
|
|
||||||
static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
|
static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0);
|
||||||
@ -1880,7 +1880,7 @@ public:
|
|||||||
seed(_Sseq& __q)
|
seed(_Sseq& __q)
|
||||||
{__seed(__q, integral_constant<unsigned,
|
{__seed(__q, integral_constant<unsigned,
|
||||||
1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
|
1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
|
||||||
: (__m-1) / 0x100000000ull)>());}
|
: (__m > 0x100000000ull))>());}
|
||||||
|
|
||||||
// generating functions
|
// generating functions
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
@ -1969,7 +1969,7 @@ linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
|
|||||||
uint32_t __ar[__k+3];
|
uint32_t __ar[__k+3];
|
||||||
__q.generate(__ar, __ar + __k + 3);
|
__q.generate(__ar, __ar + __k + 3);
|
||||||
result_type __s = static_cast<result_type>((__ar[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;
|
__x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,4 +28,12 @@ int main()
|
|||||||
e1.seed(sseq);
|
e1.seed(sseq);
|
||||||
assert(e1 == e2);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user