[Boost-bugs] [Boost C++ Libraries] #10064: generate_uniform_real may go into infinite loop

Subject: [Boost-bugs] [Boost C++ Libraries] #10064: generate_uniform_real may go into infinite loop
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-05-21 12:24:03


#10064: generate_uniform_real may go into infinite loop
-----------------------------------+---------------------------
 Reporter: Markus Faerber <mf@…> | Owner: no-maintainer
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: random
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: |
-----------------------------------+---------------------------
 See uniform_real_distribution.hpp:

 template<class Engine, class T>
 T generate_uniform_real(
     Engine& eng, T min_value, T max_value,
     boost::mpl::true_ /** is_integral<Engine::result_type> */)
 {
     for(;;) {
         typedef T result_type;
         typedef typename Engine::result_type base_result;
         result_type numerator =
 static_cast<T>(subtract<base_result>()(eng(), (eng.min)()));
         result_type divisor =
 static_cast<T>(subtract<base_result>()((eng.max)(), (eng.min)())) + 1;
         BOOST_ASSERT(divisor > 0);
         BOOST_ASSERT(numerator >= 0 && numerator <= divisor);
         T result = numerator / divisor * (max_value - min_value) +
 min_value;
         if(result < max_value) return result;
     }
 }

 Please add a "BOOST_ASSERT(max_value > min_value);".

 If one declares something like

    boost::random::mt19937 mt;
    boost::random::uniform_real_distribution<double> dist(0.0, 0.0);

 dist(mt) makes generate_uniform_real go into an infinite loop.

 Thank you and best regards.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10064>
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:50:16 UTC