Boost logo

Boost :

From: Andy Glew (glew_at_[hidden])
Date: 1999-11-09 11:33:15


> There is another possibility. What if we design the random number classes
> to use fixed precision arithmetic internally? That would avoid the overhead
> of floating-point

Be careful.

Fixed point arithmetic is often considerably WORSE performance
than floating point. Many modern machines, unfortunately, make integer
multiplications slower than floating point multiplication (actually, they
transfer the integer to the FP side, multiply, correct, and transfer back),
and the extra overhead of fixed point normalization on top of that
makes it still worse.

Recommendation: use whatever operations the designer feels are most
appropriate to a well-characterized random number generator. If integers
are the way the proof goes, use integers; if fixed point, used fixed point.
I cannot imagine anyone trying to write a portable RNG entirely in floating
point - IEEE FP is not *that* complete a standard, even as simple a
configuration change as rounding modes would hurt numeric reliability
- but if you want FP, use that.

Then provide a "raw" interface to the RNG. Typically characterized by
a lower and upper-bound of integers, between which the RNG delivers
some characterized results.

Finally, for those of us who want to use RNGs without having to worry
about the details, provide a normalized interface returning a uniform
random number on the interval [0,1). Make that [0,1) floating point,
single or double precision (or even long double, if you can - it's IEEE
standard, if not C/C++); if there is a standard fixed point format,
define an interface returning that too.


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