Opened 14 years ago

Closed 14 years ago

#2787 closed Bugs (invalid)

boost::random::detail::uniform_int_float constructor

Reported by: rick68@… Owned by: Steven Watanabe
Milestone: Boost 1.39.0 Component: random
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

Hi,

In <boost/random/detail/uniform_int_float.hpp>

line32: uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff)
line33: : _rng(rng), _min(min_arg), _max(max_arg)
line34: {
line35: init();
line36: }

line68: void init()
line69: {
line70: _range = static_cast<base_result>(_max-_min)+1;
line71: }

If IntType is "unsigned long" and "min_arg = 0", "max_arg = 0xffffffff"; after call constructor, _range will be zero. Becouse "0 + 0xffffffff + 1" is 0, so when we call operator() anytime, it always return 0. Is it normal?

Change History (3)

comment:1 by Steven Watanabe, 14 years ago

No. This is not supposed to happen. How did you run into this problem? uniform_int_float is in a detail namespace, so you shouldn't be using it directly.

comment:2 by Rick Yang <rick68@…>, 14 years ago

Hi, Yes, I directly use it. I think I shouldn't do that. :p

comment:3 by Steven Watanabe, 14 years ago

Resolution: invalid
Status: newclosed
Type: PatchesBugs

Also, base_result should be a floating point type, so as long as IntType is unsigned (and IntType is unsigned in all uses inside the random library) there should be no problem with overflow.

Note: See TracTickets for help on using tickets.