summaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-04-17 23:24:44 +0000
committerUlrich Drepper <drepper@redhat.com>1997-04-17 23:24:44 +0000
commitb75f2c28f9f9eac316e3caa30ae1fdabb406eb62 (patch)
treec2875001d90c8160104702a3df020cec362e3123 /stdlib
parent6393f70acbb63ee6c460782929bb32068d78a9f5 (diff)
(erand48_r): Build double value using ieee754_double union and use
random bits in different order to increase effect of seed.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/erand48_r.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/stdlib/erand48_r.c b/stdlib/erand48_r.c
index 17caae573c..958c2e2799 100644
--- a/stdlib/erand48_r.c
+++ b/stdlib/erand48_r.c
@@ -1,22 +1,23 @@
-/* Copyright (C) 1995 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
-
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <ieee754.h>
#include <stdlib.h>
#include <limits.h>
@@ -27,6 +28,8 @@ erand48_r (xsubi, buffer, result)
struct drand48_data *buffer;
double *result;
{
+ union ieee754_double temp;
+
/* Compute next state. */
if (__drand48_iterate (xsubi, buffer) < 0)
return -1;
@@ -35,9 +38,12 @@ erand48_r (xsubi, buffer, result)
its fractional part so the resulting FP number is [0.0,1.0). */
#if USHRT_MAX == 65535
- *result = ((double) xsubi[2] / (1ULL << 48) +
- (double) xsubi[1] / (1ULL << 32) +
- (double) xsubi[0] / (1ULL << 16));
+ temp.ieee.negative = 0;
+ temp.ieee.exponent = IEEE754_DOUBLE_BIAS - 1;
+ temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
+ temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
+ /* Please note the lower 4 bits of mantissa1 are always 0. */
+ *result = temp.d;
#else
# error Unsupported size of short int
#endif