Mail Archives: djgpp-workers/2000/05/19/07:59:53
Dieter said:
> On 27 Apr 00, at 14:05, Martin Stromberg wrote:
> > In particular I wonder how the ones generating doubles
> > (drand48(), erand48()) behave, as I improvised most on them.
>
> My manpages don't document the method, that should be
> used, to create a [0,1[ double. If I understand your code correctly,
> you "mix" the bits of the three state variables.
>
> return
> (b16s2,b16s1,b16s0,b15s2,b15s1,b15s0, ..., b1s2,b1s1,b1s0)/2^48.
>
> (b16s2 is the most significant bit of s2, and so on ...)
>
> A more natural approach seems to me to just do
>
> s2*2^-16 + s1*2^-32 + s0*2^-48;
>
> Doing this with floating point arithmetics will always yield "exact"
> results, no rounding will be involved with binary floating point
> representation.
>
> Reason for my suggestion: s0 is not very random at all (period 2^16).
> With the "mixing method", information of s0 will creep into the most
> significant digits of the returned double.
Ok, how doI easily say 2^-16, 2^-32 and 2^-48 to the compiler? Is it
ok to use pow(2, -16) etc. (efficiency)?
Right,
MartinS
- Raw text -