Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51120 - in trunk: boost/random libs/random
From: steven_at_[hidden]
Date: 2009-02-08 18:50:57


Author: steven_watanabe
Date: 2009-02-08 18:50:56 EST (Sun, 08 Feb 2009)
New Revision: 51120
URL: http://svn.boost.org/trac/boost/changeset/51120

Log:
correctly detect the end of the range in lagged_fibonacci_01::seed. Fixes #2703
Text files modified:
   trunk/boost/random/lagged_fibonacci.hpp | 6 ++++--
   trunk/libs/random/random_test.cpp | 16 ++++++++--------
   2 files changed, 12 insertions(+), 10 deletions(-)

Modified: trunk/boost/random/lagged_fibonacci.hpp
==============================================================================
--- trunk/boost/random/lagged_fibonacci.hpp (original)
+++ trunk/boost/random/lagged_fibonacci.hpp 2009-02-08 18:50:56 EST (Sun, 08 Feb 2009)
@@ -317,12 +317,14 @@
     unsigned long mask = ~((~0u) << (w%32)); // now lowest w bits set
     RealType two32 = pow(RealType(2), 32);
     unsigned int j;
- for(j = 0; j < long_lag && first != last; ++j, ++first) {
+ for(j = 0; j < long_lag && first != last; ++j) {
       x[j] = RealType(0);
       for(int k = 0; k < w/32 && first != last; ++k, ++first)
         x[j] += *first / pow(two32,k+1);
- if(first != last && mask != 0)
+ if(first != last && mask != 0) {
         x[j] += fmod((*first & mask) / _modulus, RealType(1));
+ ++first;
+ }
     }
     i = long_lag;
     if(first == last && j < long_lag)

Modified: trunk/libs/random/random_test.cpp
==============================================================================
--- trunk/libs/random/random_test.cpp (original)
+++ trunk/libs/random/random_test.cpp 2009-02-08 18:50:56 EST (Sun, 08 Feb 2009)
@@ -238,17 +238,17 @@
   std::vector<int>::const_iterator it_end = v.end();
   URNG urng3(it, it_end);
   BOOST_CHECK(it != v.begin());
- std::cout << "; seeding uses " << (it - v.begin()) << " words" << std::endl;
+ std::vector<int>::const_iterator::difference_type n_words = (it - v.begin());
+ std::cout << "; seeding uses " << n_words << " words" << std::endl;
 
- bool have_exception = false;
- try {
- // now check that exceptions are thrown
+ it = v.end();
+ BOOST_CHECK_THROW(urng3.seed(it, it_end), std::invalid_argument);
+
+ if(n_words > 1) {
     it = v.end();
- urng3.seed(it, it_end);
- } catch(std::invalid_argument& x) {
- have_exception = true;
+ --it;
+ BOOST_CHECK_THROW(urng3.seed(it, it_end), std::invalid_argument);
   }
- BOOST_CHECK(have_exception);
 
   // check for min/max members
   ResultType min = (urng3.min)();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk