diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-04-20 11:37:26 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-04-20 11:37:26 +0300 |
commit | 975fbde5ddb54b76212f25e5f114758ebf91f572 (patch) | |
tree | b06cce38a8ac41dfa146c8e1e9da2bf98909bcdf /builtin.c | |
parent | 698f8a9414180fc1243de799126dcbb57c86592a (diff) | |
download | egawk-975fbde5ddb54b76212f25e5f114758ebf91f572.tar.gz egawk-975fbde5ddb54b76212f25e5f114758ebf91f572.tar.bz2 egawk-975fbde5ddb54b76212f25e5f114758ebf91f572.zip |
Fix do_rand order-of-evaluation dependency.
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -2454,8 +2454,14 @@ do_rand(int nargs ATTRIBUTE_UNUSED) */ do { - tmprand = 0.5 + ( (random()/RAND_DIVISOR + random()) - / RAND_DIVISOR); + long d1, d2; + /* + * Do the calls in predictable order to avoid + * compiler differences in order of evaluation. + */ + d1 = random(); + d2 = random(); + tmprand = 0.5 + ( (d1/RAND_DIVISOR + d2) / RAND_DIVISOR ); tmprand -= 0.5; } while (tmprand == 1.0); |