Boost logo

Boost :

From: Stephan Tolksdorf (andorxor_at_[hidden])
Date: 2006-08-08 16:38:48


>>> * a clumsy (and inexact) interface between the random generators and
>>> the random distributions.
>> I wonder what you refer to here?
>
> Here's one example. In bernoulli_distribution we have
>
> if(_p == RealType(0))
> return false;
> else
> return RealType(eng() - (eng.min)()) <=
> _p * RealType((eng.max)()-(eng.min)());
>
> where eng() returns integers between eng.min() and eng.max() incl. The
> problems are:
>
> * If the integers returned by eng() are signed (e.g.,
> linear_congruential) then eng() - (eng.min)() and (eng.max)() -
> (eng.min)() can overflow and the results are bogus.
> (...)

RealType(eng() - (eng.min)()) could just be replaced with
RealType(eng()) - RealType((eng.min)()), or alternatively template
metaprogramming techniques be applied (result_type, min and max are
compile time constants in the standard proposal).

> * The results depend on the granularity of the underlying engine. Why
> not return an exact result? The answer lies in the overall structure
> of the library where the bernoulli is expected to use the raw numbers
> coming out of the generator. If there were a
> uniform_float01<RealType>(eng);

See the generate_canonical template function in the standard proposal.

(...)
>> template<class Engine>
>> result_type operator()(Engine& eng)
>>
>> is sometimes awkward. It doesn't allow compile-time inquiry of the
>> engine properties by the distribution class.

min and max are static constants in the standard proposal, so there's no
general problem with compile time inspection.

Stephan


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