From: Ulrich Drepper Date: Thu, 17 Apr 1997 23:24:44 +0000 (+0000) Subject: (erand48_r): Build double value using ieee754_double union and use X-Git-Tag: cvs/libc20x-ud-970417~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b75f2c28f9f9eac316e3caa30ae1fdabb406eb62;p=thirdparty%2Fglibc.git (erand48_r): Build double value using ieee754_double union and use random bits in different order to increase effect of seed. --- diff --git a/stdlib/erand48_r.c b/stdlib/erand48_r.c index 17caae573cf..958c2e2799a 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 , 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 , 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 #include #include @@ -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