Boost logo

Boost :

From: Daniel James (daniel_james_at_[hidden])
Date: 2006-03-18 04:56:05

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!

This seems to be dependant on the type of generator you use. Try using
lagged_fibonacci. The casting and dividing involved in uniform_real
appears to loose a lot of accuracy, but lagged_fibonacci generates
doubles between 0 and 1, so there's no cast and it's dividing by 1.

Interestingly, minstd_rand also seems to work better. Purely
speculatively, I think this might be because of the ranges of values it
generates - with mt19937 the random number is divided by 0xffffffff,
while for minstd_rand it is divided by 0x7ffffffd. Although, I wouldn't
be surprised if it performs badly by some other measure.

Come to think of it, uniform_real is meant to be generating a half-open
range - so maybe it should be diving by (max() - min() + 1) for
integers. Looking at the concept documentation: 'For integer generators
(i.e. integer T), the generated values x fulfill min() <= x <= max(),
for non-integer generators (i.e. non-integer T), the generated values x
fulfill min() <= x < max().'

Or are you only meant to use floaing point generators when generating a
floating point distribution?


Boost list run by bdawes at, gregod at, cpdaniel at, john at