This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/39644 (partial)


Hi,

sanity-checked x86_64-linux, committed to mainline.

Paolo.

/////////////////
2009-04-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/39644 (partial)
	* include/bits/random.tcc (linear_congruential_engine<>::
	seed(seed_seq&), independent_bits_engine<>::operator(),
	generate_canonical(_UniformRandomNumberGenerator&)): Avoid log2l.
Index: include/bits/random.tcc
===================================================================
--- include/bits/random.tcc	(revision 145559)
+++ include/bits/random.tcc	(working copy)
@@ -118,7 +118,9 @@
     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 @@
         }
 
       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 @@
     {
       const long double __r = static_cast<long double>(this->max())
 			    - static_cast<long double>(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 @@
                    __bits);
       const long double __r = static_cast<long double>(__urng.max())
 			    - static_cast<long double>(__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<size_t>(1UL, (__b + __log2r - 1UL) / __log2r);
       _RealType __sum = _RealType(0);
       _RealType __tmp = _RealType(1);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]