]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(erand48_r): Build double value using ieee754_double union and use
authorUlrich Drepper <drepper@redhat.com>
Thu, 17 Apr 1997 23:24:44 +0000 (23:24 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 17 Apr 1997 23:24:44 +0000 (23:24 +0000)
random bits in different order to increase effect of seed.

stdlib/erand48_r.c

index 17caae573cfb399c12ada07759f0d58b6917e3d4..958c2e2799a986e1ef492b1be8fdd4395ee56608 100644 (file)
@@ -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