[Boost-bugs] [Boost C++ Libraries] #2703: lagged_fibonacci_01::seed() bug

Subject: [Boost-bugs] [Boost C++ Libraries] #2703: lagged_fibonacci_01::seed() bug
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-01-31 14:28:05


#2703: lagged_fibonacci_01::seed() bug
------------------------------+---------------------------------------------
 Reporter: rick68_at_[hidden] | Owner: no-maintainer
     Type: Bugs | Status: new
Milestone: Boost 1.38.0 | Component: random
  Version: Boost 1.37.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 Hi,

 In <boost/random/lagged_fibonacci_01.hpp>

 line309: template<class It>[[BR]]
 line310: void seed(It& first, It last)[[BR]]
 line311: {[[BR]]
 line312:#ifndef BOOST_NO_STDC_NAMESPACE[[BR]]
 line313: // allow for Koenig lookup[[BR]]
 line314: using std::fmod;[[BR]]
 line315: using std::pow;[[BR]]
 line316:#endif[[BR]]
 line317: unsigned long mask = ~((~0u) << (w%32)); // now lowest w
 bits set[[BR]]
 line318: RealType two32 = pow(RealType(2), 32);[[BR]]
 line319: unsigned int j;[[BR]]
 line320: for(j = 0; j < long_lag && first != last; ++j, ++first)
 {[[BR]]
 line312: x[j] = RealType(0);[[BR]]
 line313: for(int k = 0; k < w/32 && first != last; ++k,
 ++first)[[BR]]
 line314: x[j] += *first / pow(two32,k+1);[[BR]]
 line315: if(first != last && mask != 0)[[BR]]
 line316: x[j] += fmod((*first & mask) / _modulus,
 RealType(1));[[BR]]
 line317: }[[BR]]
 line318: i = long_lag;[[BR]]
 line319: if(first == last && j < long_lag)[[BR]]
 line320: throw
 std::invalid_argument("lagged_fibonacci_01::seed");[[BR]]
 line321: }[[BR]]

 line 313 maybe rewrite to:

       for(int k = 0; k < w/32 && first != last; ++k)

 because of the first "for loop" can't be broken.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2703>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC