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

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2703: lagged_fibonacci_01::seed() bug
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-02-01 05:58:54


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

 * cc: rick68_at_[hidden] (added)
  * status: closed => reopened
  * resolution: invalid =>

Comment:

 Replying to [comment:1 steven_watanabe]:
> This is not a bug. The value_type of the
> iterator is assumed to be a 32 bit integer, while
> RealType is usually a double. The loop is needed
> because RealType may have more bits of precision than
> the iterator's value_type. Thus, more than one element
> of the input range may be needed to initialize a single
> element of the state. Therefore the iterator needs
> to be incremented in the inner loop.

 Hi,

 I tried this test code:

 ================================================================================[[BR]]
 #include <iostream>[[BR]]
 #include <vector>[[BR]]
 #include <stdexcept>[[BR]]

 #include <boost/cstdlib.hpp>[[BR]]
 #include <boost/cstdint.hpp>[[BR]]
 #include <boost/random/lagged_fibonacci.hpp>[[BR]]

 int main(void)
 {
     typedef std::vector<boost::int32_t> seed_type;[[BR]]

     boost::lagged_fibonacci607 gen;[[BR]]
     seed_type seed(gen.long_lag);[[BR]]
     seed_type::iterator first;[[BR]]
     seed_type::iterator second;[[BR]]


     std::cout << "(second - first) = [" << (second - first) << ']' <<
 std::endl;[[BR]]

     first = seed.begin();[[BR]]
     second = seed.end();[[BR]]
     std::cout << "(second - first) = [" << (second - first) << ']' <<
 std::endl;[[BR]]

     try {
         gen.seed(first, second);[[BR]]
     } catch (const std::invalid_argument& e)
     {
         std::cout << e.what() << std::endl;[[BR]]
     }

     std::cout << "(second - first) = [" << (second - first) << ']' <<
 std::endl;[[BR]]


     return boost::exit_success;[[BR]]
 }
 ================================================================================

 And this is my result:[[BR]]
 =================================[[BR]]
 (second - first) = [0] [[BR]]
 (second - first) = [607] [[BR]]
 (second - first) = [-607] [[BR]]
 =================================[[BR]]
 [[BR]]
 I can't catch any exception, and member function "gen.seed()" will out of
 range.[[BR]]

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2703#comment:2>
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