Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2002-03-11 15:33:47


Douglas Gregor wrote:
>
> This code in uniform_int:
> 120 if(_brange / _range > 4 /* quantization_cutoff */ ) {
> 121 // the new range is vastly smaller than the source range,
> 122 // so quantization effects are not relevant
> 123 return uniform_smallint<base_type,result_type>(_rng, _min, _max)();
> 124 } else {
>
> will make uniform_smallint do very bad things when _max-_min+1 is large
> enough to make 32*_range*_range (where _range = _max-_min+1 at line 95 of
> uniform_smallint.hpp) overflow and become negative. Then we get stuck in the
> following loop forever (uniform_smallint.hpp):
>
> 95 const base_result r = 32*_range*_range;
> 96 for(; r_base >= r; _factor *= 2)
> 97 r_base /= 2;
>
> I don't know enough about this to know if uniform_int should take care of
> this (and not deflect to uniform_smallint if it would overflow), or if
> uniform_smallint should deal with this overflow itself.

Indeed. uniform_smallint<> should cope with the input. I've fixed it in the
CVS.

Thanks for the report.

Jens Maurer


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk