OSDN Git Service

2012-11-01 Haakan Younes <hyounes@google.com>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 1 Nov 2012 21:09:51 +0000 (21:09 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 1 Nov 2012 21:09:51 +0000 (21:09 +0000)
     Paolo Carlini  <paolo.carlini@oracle.com>

PR libstdc++/55047
* include/bits/random.h (exponential_distribution<>::operator):
Fix formula to std::log(result_type(1) - __aurng()).
* include/bits/random.tcc: Likewise, everywhere.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@193070 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/random.h
libstdc++-v3/include/bits/random.tcc

index aab18f5..b3302bf 100644 (file)
@@ -1,3 +1,11 @@
+2012-11-01   Haakan Younes  <hyounes@google.com>
+            Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR libstdc++/55047
+       * include/bits/random.h (exponential_distribution<>::operator):
+       Fix formula to std::log(result_type(1) - __aurng()).
+       * include/bits/random.tcc: Likewise, everywhere.
+
 2012-10-29  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
         PR libstdc++/55123
index aa4ce3e..a0ee556 100644 (file)
@@ -1,6 +1,6 @@
 // random number generation -*- C++ -*-
 
-// Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2009-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -4247,7 +4247,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        {
          __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
            __aurng(__urng);
-         return -std::log(__aurng()) / __p.lambda();
+         return -std::log(result_type(1) - __aurng()) / __p.lambda();
        }
 
     private:
index 5b90e5a..1dfa9fb 100644 (file)
@@ -1,6 +1,6 @@
 // random number generation (out of line) -*- C++ -*-
 
-// Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2009-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -1053,7 +1053,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
        double __cand;
        do
-         __cand = std::floor(std::log(__aurng()) / __param._M_log_1_p);
+         __cand = std::floor(std::log(1.0 - __aurng()) / __param._M_log_1_p);
        while (__cand >= __thr);
 
        return result_type(__cand + __naf);
@@ -1258,7 +1258,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            do
              {
                const double __u = __c * __aurng();
-               const double __e = -std::log(__aurng());
+               const double __e = -std::log(1.0 - __aurng());
 
                double __w = 0.0;
 
@@ -1290,7 +1290,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                  __x = 1;
                else
                  {
-                   const double __v = -std::log(__aurng());
+                   const double __v = -std::log(1.0 - __aurng());
                    const double __y = __param._M_d
                                     + __v * __2cx / __param._M_d;
                    __x = std::ceil(__y);
@@ -1434,7 +1434,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
        do
          {
-           const double __e = -std::log(__aurng());
+           const double __e = -std::log(1.0 - __aurng());
            __sum += __e / (__t - __x);
            __x += 1;
          }
@@ -1502,7 +1502,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    __reject = __y >= __param._M_d1;
                    if (!__reject)
                      {
-                       const double __e = -std::log(__aurng());
+                       const double __e = -std::log(1.0 - __aurng());
                        __x = std::floor(__y);
                        __v = -__e - __n * __n / 2 + __param._M_c;
                      }
@@ -1514,15 +1514,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    __reject = __y >= __param._M_d2;
                    if (!__reject)
                      {
-                       const double __e = -std::log(__aurng());
+                       const double __e = -std::log(1.0 - __aurng());
                        __x = std::floor(-__y);
                        __v = -__e - __n * __n / 2;
                      }
                  }
                else if (__u <= __a123)
                  {
-                   const double __e1 = -std::log(__aurng());
-                   const double __e2 = -std::log(__aurng());
+                   const double __e1 = -std::log(1.0 - __aurng());
+                   const double __e2 = -std::log(1.0 - __aurng());
 
                    const double __y = __param._M_d1
                                     + 2 * __s1s * __e1 / __param._M_d1;
@@ -1533,8 +1533,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                  }
                else
                  {
-                   const double __e1 = -std::log(__aurng());
-                   const double __e2 = -std::log(__aurng());
+                   const double __e1 = -std::log(1.0 - __aurng());
+                   const double __e2 = -std::log(1.0 - __aurng());
 
                    const double __y = __param._M_d2
                                     + 2 * __s2s * __e1 / __param._M_d2;
@@ -2136,7 +2136,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
        __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
          __aurng(__urng);
-       return __p.b() * std::pow(-std::log(__aurng()),
+       return __p.b() * std::pow(-std::log(result_type(1) - __aurng()),
                                  result_type(1) / __p.a());
       }
 
@@ -2194,7 +2194,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
        __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
          __aurng(__urng);
-       return __p.a() - __p.b() * std::log(-std::log(__aurng()));
+       return __p.a() - __p.b() * std::log(-std::log(result_type(1)
+                                                     - __aurng()));
       }
 
   template<typename _RealType, typename _CharT, typename _Traits>