From: Paolo Carlini Date: Sun, 5 Apr 2009 16:56:16 +0000 (+0000) Subject: PR libstdc++/39644 (partial) X-Git-Tag: releases/gcc-4.5.0~6894 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fcf6ffb76998fd44284bc6d77503966ac36e30c;p=thirdparty%2Fgcc.git PR libstdc++/39644 (partial) 2009-04-05 Paolo Carlini PR libstdc++/39644 (partial) * include/bits/random.tcc (linear_congruential_engine<>:: seed(seed_seq&), independent_bits_engine<>::operator(), generate_canonical(_UniformRandomNumberGenerator&)): Avoid log2l. From-SVN: r145563 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 10aab8317337..10014eb2f763 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2009-04-05 Paolo Carlini + + PR libstdc++/39644 (partial) + * include/bits/random.tcc (linear_congruential_engine<>:: + seed(seed_seq&), independent_bits_engine<>::operator(), + generate_canonical(_UniformRandomNumberGenerator&)): Avoid log2l. + 2009-04-04 Edward Smith-Rowland <3dw4rd@verizon.net> * include/bits/random.h (struct _ShiftMin1): Fix small typo and diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 022335adc178..bfd017a99340 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -118,7 +118,9 @@ namespace std linear_congruential_engine<_UIntType, __a, __c, __m>:: seed(seed_seq& __q) { - const _UIntType __k = (std::log2(__m) + 31) / 32; + const _UIntType __k0 = __m == 0 ? std::numeric_limits<_UIntType>::digits + : (std::__lg(__m) + 31); + const _UIntType __k = __k0 / 32; _UIntType __arr[__k + 3]; __q.generate(__arr + 0, __arr + 3); _UIntType __factor = 1U; @@ -130,7 +132,7 @@ namespace std } if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U) - && (__detail::__mod<_UIntType, 1U, 0U, __m>(__sum) == 0U)) + && (__detail::__mod<_UIntType, 1U, 0U, __m>(__sum) == 0U)) _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U); else _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__sum); @@ -578,7 +580,7 @@ namespace std { const long double __r = static_cast(this->max()) - static_cast(this->min()) + 1.0L; - const result_type __m = std::log2l(__r); + const result_type __m = std::log10(__r) / std::log10(2.0L); result_type __n, __n0, __y0, __y1, __s0, __s1; for (size_t __i = 0; __i < 2; ++__i) { @@ -2762,7 +2764,7 @@ namespace std __bits); const long double __r = static_cast(__urng.max()) - static_cast(__urng.min()) + 1.0L; - const size_t __log2r = std::log2l(__r); + const size_t __log2r = std::log10(__r) / std::log10(2.0L); size_t __k = std::max(1UL, (__b + __log2r - 1UL) / __log2r); _RealType __sum = _RealType(0); _RealType __tmp = _RealType(1);