diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2013-10-17 22:08:24 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2013-10-17 22:08:24 +0300 |
commit | a0ca839420118a77a19a8ab05d08f58a076edd17 (patch) | |
tree | 343a5e52de5171344e94415a951c1d781ff28411 | |
parent | 45ebe190c01c030e82483a9ef5d032aba32dad1f (diff) | |
download | egawk-a0ca839420118a77a19a8ab05d08f58a076edd17.tar.gz egawk-a0ca839420118a77a19a8ab05d08f58a076edd17.tar.bz2 egawk-a0ca839420118a77a19a8ab05d08f58a076edd17.zip |
Additional fix in do_rand.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | builtin.c | 11 |
2 files changed, 11 insertions, 5 deletions
@@ -3,6 +3,11 @@ * main.c (main): Ignore SIGPIPE. See the comment in the code. Thanks to Alan Broder for reporting the issue. + Unrelated: + + * rand.c (do_rand): Fix computation and loop checking against + 1.0 to use do..while. + 2013-10-16 Arnold D. Robbins <arnold@skeeve.com> Make -O work again. Turns out that C99 bool variables @@ -2432,12 +2432,13 @@ do_rand(int nargs ATTRIBUTE_UNUSED) * } */ - tmprand = 0.5 + ( (random()/RAND_DIVISOR + random()) / RAND_DIVISOR); + do { + tmprand = 0.5 + ( (random()/RAND_DIVISOR + random()) + / RAND_DIVISOR); + tmprand -= 0.5; + } while (tmprand == 1.0); - while (tmprand == 1.0) - tmprand = 0.5 + ( (random()/RAND_DIVISOR + random()) / RAND_DIVISOR); - - return make_number((AWKNUM) (tmprand - 0.5)); + return make_number((AWKNUM) tmprand); } /* do_srand --- seed the random number generator */ |