Subject: [Boost-bugs] [Boost C++ Libraries] #6059: uniform_real_distribution fails when _min = _max
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-10-25 19:53:38
#6059: uniform_real_distribution fails when _min = _max
---------------------------------------+------------------------------------
Reporter: dario.izzo@⦠| Owner: steven_watanabe
Type: Bugs | Status: new
Milestone: To Be Determined | Component: random
Version: Boost 1.47.0 | Severity: Problem
Keywords: |
---------------------------------------+------------------------------------
Connected to BUG report #6053.
Even though all asserts require only that _min <= _max, the condition
_min=_max seems to be not handled correctly. Consider the code
{{{
#include<boost/random/uniform_real_distribution.hpp>
#include<boost/random/lagged_fibonacci.hpp>
#include<iostream>
int main() {
boost::lagged_fibonacci607 rng(32);
double r = boost::random::uniform_real_distribution<double>(90,91)(rng);
std::cout << r << std::endl;
r = boost::random::uniform_real_distribution<double>(50,50)(rng);
std::cout << r << std::endl;
return 0;
}
}}}
the second std::cout will never execute as an infinite loop is encountered
before. The problem is in boost/random/uniform_real_distribution.hpp and
in particular at generate_uniform_real line:
{{{
if(result < max_value) return result;
}}}
If min_value == max_value the condition above is never met as result =
min_value = max_value ALWAYS.
A solution (the one I am currently using) could be
{{{
if ( (result < max_value) || (max_value==min_value) ) return result;
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6059> 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:07 UTC