Boost logo

Boost :

From: Manfred Doudar (manfred.doudar_at_[hidden])
Date: 2006-03-18 02:28:30


Hi John,

John Maddock wrote:
> I seriously hope I'm doing something wrong here, but the last 20 bits in a
> double returned from uniform_real appear to always be zero. Is this by
> design? I really hope not!
>
> Here's the test code:
>
> template <class T>
> void test_random(T)
> {
> boost::mt19937 rnd;
> boost::uniform_real<T> ur_a(0.5, 1);
> boost::variate_generator<std::tr1::mt19937, std::tr1::uniform_real<T> >
> gen(rnd, ur_a);
> for(int j = 0; j < INT_MAX-2; ++j)
> {
> T v = gen();
> // get the digits of T:
> unsigned long long i = (unsigned long long)std::floor(std::ldexp(v,
> std::numeric_limits<T>::digits));
> i &= 0xfffff; // last 20 bits
> std::cout << std::hex << i << std::endl;
> }
> }
>
> Try calling with a double as an argument and it'll output nothing but
> zero's.
>

If memory serves, I've hit on this before - but I don't think you'll
like answer - you're going to have to push the variate_generator gen (,
and its dependants rnd, and ur_a) into the global namespace.

Cheers,

-- 
18.03.2006
Manfred Doudar - Research Engineer
National ICT Australia (NICTA)
Research School of Information Sciences and Engineering (RSISE)
The Australian National University - Canberra, ACT 0200 AUSTRALIA

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