Boost C++ Libraries: Ticket #2787: boost::random::detail::uniform_int_float constructor https://svn.boost.org/trac10/ticket/2787 <p> Hi, </p> <p> In &lt;boost/random/detail/uniform_int_float.hpp&gt; </p> <p> line32: uniform_int_float(base_type rng, <a class="missing wiki">IntType</a> min_arg = 0, <a class="missing wiki">IntType</a> max_arg = 0xffffffff)<br /> line33: : _rng(rng), _min(min_arg), _max(max_arg)<br /> line34: {<br /> line35: init();<br /> line36: }<br /> </p> <p> line68: void init()<br /> line69: {<br /> line70: _range = static_cast&lt;base_result&gt;(_max-_min)+1;<br /> line71: }<br /> </p> <p> If <a class="missing wiki">IntType</a> 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? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2787 Trac 1.4.3 Steven Watanabe Sat, 21 Feb 2009 16:15:16 GMT <link>https://svn.boost.org/trac10/ticket/2787#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2787#comment:1</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>Rick Yang <rick68@…></author> <pubDate>Sat, 21 Feb 2009 16:24:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2787#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2787#comment:2</guid> <description> <p> Hi, Yes, I directly use it. I think I shouldn't do that. :p </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Mon, 23 Feb 2009 01:42:46 GMT</pubDate> <title>status, type changed; resolution set https://svn.boost.org/trac10/ticket/2787#comment:3 https://svn.boost.org/trac10/ticket/2787#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>type</strong> <span class="trac-field-old">Patches</span> → <span class="trac-field-new">Bugs</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Also, <code>base_result</code> should be a floating point type, so as long as <code>IntType</code> is unsigned (and <code>IntType</code> is unsigned in all uses inside the random library) there should be no problem with overflow. </p> Ticket