Mercurial > octave
changeset 27858:797be8d10c22
Create equally-spaced floating point values for rand ("double").
* randmtzig.cc (randu53): Test and exclude value of 0 (left endpoint of range).
Remove offset addition of 0.4 when constructing output which causes first
interval to be unequally sized compared to all others (which are of size
eps/2).
author | Rik <rik@octave.org> |
---|---|
date | Fri, 20 Dec 2019 14:36:03 -0800 |
parents | 81ada4b7d85b |
children | 1a75fca6ad5d |
files | liboctave/numeric/randmtzig.cc |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/numeric/randmtzig.cc Fri Dec 20 14:25:16 2019 -0800 +++ b/liboctave/numeric/randmtzig.cc Fri Dec 20 14:36:03 2019 -0800 @@ -393,9 +393,16 @@ /* generates a random number on (0,1) with 53-bit resolution */ static double randu53 (void) { - const uint32_t a = randi32 () >> 5; - const uint32_t b = randi32 () >> 6; - return (a*67108864.0+b+0.4) * (1.0/9007199254740992.0); + int32_t a, b; + + do + { + a = randi32 () >> 5; + b = randi32 () >> 6; + } + while (a == 0 && b == 0); + + return (a*67108864.0 + b) * (1.0/9007199254740992.0); } /* Determine mantissa for uniform doubles */