Re: [Boost-bugs] [Boost C++ Libraries] #819: uniform_int<> with type's maximum availaible range error

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #819: uniform_int<> with type's maximum availaible range error
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-02-09 01:13:05


#819: uniform_int<> with type's maximum availaible range error
---------------------+------------------------------------------------------
  Reporter: nobody | Owner: no-maintainer
      Type: Bugs | Status: new
 Milestone: | Component: random
   Version: None | Severity: Problem
Resolution: None | Keywords:
---------------------+------------------------------------------------------
Changes (by marshall):

  * owner: jmaurer => no-maintainer
  * status: assigned => new
  * severity: => Problem

Old description:

> {{{
> using boost 1_33_1, MSVC 8.0
> using namespace boost;
> using namespace std;
>
> typedef int32_t IntType;// the same bug for int8_t int16_t int64_t
>
> uniform_int<IntType> ui(numeric_limits<IntType>::min(),
> numeric_limits<IntType>::max());
> rand48 rng;
> variate_generator<rand48, uniform_int<int32_t> > gen(rng, ui);
> IntType x = gen(); // infinite loop here
> If we makes range smaller or if we using unsigned types - everything is
> OK
> So if we will look to uniform_int.hpp we will see.....
> template<class IntType = int>
> class uniform_int
> {
> public:
> ....
> typedef IntType result_type;
> ....
> explicit uniform_int(IntType min = 0, IntType max = 9)
> : _min(min), _max(max)
> {
> ......
> assert(min <= max); init();
> }.....
> private:
> result_type _min, _max, _range;
> void init()
> {
> _range = _max - _min;// for SIGNED types and maximum available range
> we will receive..... of course -1 !!!!!! }
> ......}Also i want to draw the attention russian-speaking boost
> developers to the http://rsdn.ru/Forum/Message.aspx?mid=2252961&only=1
> }}}

New description:

 {{{
 using boost 1_33_1, MSVC 8.0
 using namespace boost;
 using namespace std;

 typedef int32_t IntType;// the same bug for int8_t int16_t int64_t

 uniform_int<IntType> ui(numeric_limits<IntType>::min(),
 numeric_limits<IntType>::max());
 rand48 rng;
 variate_generator<rand48, uniform_int<int32_t> > gen(rng, ui);
 IntType x = gen(); // infinite loop here
 If we makes range smaller or if we using unsigned types - everything is OK
 So if we will look to uniform_int.hpp we will see.....
 template<class IntType = int>
 class uniform_int
 {
 public:
 ....
   typedef IntType result_type;
 ....
   explicit uniform_int(IntType min = 0, IntType max = 9)
     : _min(min), _max(max)
   {
 ......
     assert(min <= max); init();
   }.....
 private:
   result_type _min, _max, _range;
   void init()
   {
     _range = _max - _min;// for SIGNED types and maximum available range
 we will receive..... of course -1 !!!!!! }
 ......}Also i want to draw the attention russian-speaking boost developers
 to the http://rsdn.ru/Forum/Message.aspx?mid=2252961&only=1
 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/819#comment:1>
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:57 UTC