From 975fbde5ddb54b76212f25e5f114758ebf91f572 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 20 Apr 2014 11:37:26 +0300 Subject: Fix do_rand order-of-evaluation dependency. --- builtin.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 875b3e5c..3464dc21 100644 --- a/builtin.c +++ b/builtin.c @@ -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); -- cgit v1.2.3