aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2004-06-13 22:58:30 +0000
committerPaul Brook <pbrook@gcc.gnu.org>2004-06-13 22:58:30 +0000
commita9e7b9d395c19da3ee99fae73d4d0f3e3a3121f5 (patch)
tree87140abfa92875e6ac3d94de1530eac1b616417c /libgfortran/intrinsics
parent3bce843ee30206917ccdfbf283c73e19a2ce633c (diff)
downloadgcc-a9e7b9d395c19da3ee99fae73d4d0f3e3a3121f5.zip
gcc-a9e7b9d395c19da3ee99fae73d4d0f3e3a3121f5.tar.gz
gcc-a9e7b9d395c19da3ee99fae73d4d0f3e3a3121f5.tar.bz2
Makefile.am (gfor_helper_src): Add runtime/normalize.f90.
* Makefile.am (gfor_helper_src): Add runtime/normalize.f90. * configure.ac: Add checks for nextafter and nextafterf. * Makefile.in, config.h.in, configure: Regenerate. * libgfortran.h (normalize_r4_i4, normalize_r8_i8): Declare. * intrinsics/rand.c (rand): Use normalize_r4_i4. * intrinsics/random.c (random_r4): Use normalize_r4_i4. (random_r8): Use normalize_r8_i8. * runtime/normalize.c: New file. testsuite/ * gfortran.fortran-torture/execute/random_2.f90: New test. From-SVN: r83070
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r--libgfortran/intrinsics/rand.c11
-rw-r--r--libgfortran/intrinsics/random.c26
2 files changed, 10 insertions, 27 deletions
diff --git a/libgfortran/intrinsics/rand.c b/libgfortran/intrinsics/rand.c
index c4782fc..d9add00 100644
--- a/libgfortran/intrinsics/rand.c
+++ b/libgfortran/intrinsics/rand.c
@@ -77,17 +77,10 @@ prefix(irand) (GFC_INTEGER_4 *i)
}
-/* Return a REAL in the range [0,1). Cast to double to use the full
- range of pseudo-random numbers returned by irand(). */
+/* Return a random REAL in the range [0,1). */
GFC_REAL_4
prefix(rand) (GFC_INTEGER_4 *i)
{
- GFC_REAL_4 val;
-
- do
- val = (GFC_REAL_4)((double)(prefix(irand) (i) - 1) / (double) GFC_RAND_M1);
- while (val == 1.0);
-
- return val;
+ return normalize_r4_i4 (i - 1, GFC_RAND_M1);
}
diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/random.c
index ef09d85..b498684 100644
--- a/libgfortran/intrinsics/random.c
+++ b/libgfortran/intrinsics/random.c
@@ -458,16 +458,11 @@ prefix(random_r4) (GFC_REAL_4 *x)
GFC_UINTEGER_4 kiss;
- do
- {
- kiss = kiss_random_kernel ();
- *x = (GFC_REAL_4)kiss / (GFC_REAL_4)(~(GFC_UINTEGER_4) 0);
- /* Burn a random number, so the REAL*4 and REAL*8 functions
- produce similar sequences of random numbers. */
- kiss = kiss_random_kernel ();
- }
- while (*x == 1.0);
-
+ kiss = kiss_random_kernel ();
+ /* Burn a random number, so the REAL*4 and REAL*8 functions
+ produce similar sequences of random numbers. */
+ kiss_random_kernel ();
+ *x = normalize_r4_i4 (kiss, ~(GFC_UINTEGER_4) 0);
}
/* This function produces a REAL(8) value from the uniform distribution
@@ -479,14 +474,9 @@ prefix(random_r8) (GFC_REAL_8 *x)
GFC_UINTEGER_8 kiss;
- do
- {
- kiss = (((GFC_UINTEGER_8)kiss_random_kernel ()) << 32)
- + kiss_random_kernel ();
- *x = (GFC_REAL_8)kiss / (GFC_REAL_8)(~(GFC_UINTEGER_8) 0);
- }
- while (*x == 1.0);
-
+ kiss = ((GFC_UINTEGER_8)kiss_random_kernel ()) << 32;
+ kiss += kiss_random_kernel ();
+ *x = normalize_r8_i8 (kiss, ~(GFC_UINTEGER_8) 0);
}
/* This function fills a REAL(4) array with values from the uniform