[gfortran] PATCH -- Fix for PR 15619
Paul Brook
paul@codesourcery.com
Sat May 29 18:40:00 GMT 2004
> Sigh. I really didn't want to become an expert on PRNG. I only
> want to use them. :-) So, here's my current solution.
In leu of approach, However:
+#ifdef __FreeBSD__
+# include <sys/uio.h>
+# include <unistd.h>
+#endif
Definitely not. Why is this needed? It should be a proper configure check.
+const GFC_INTEGER_4
+ kiss_default_seed[4] = {123456789, 362436069, 521288629, 916191069};
+static GFC_INTEGER_4
+ kiss_seed[4] = {123456789, 362436069, 521288629, 916191069};
Shouldn't these seed values use unsigned types? You're doing right shifts on
the, so it will affect the value.
+/* kiss_random_kernel() returns an integer value in the range of
+ [- GFC_INTEGER_4_HUGE, GFC_INTEGER_4_HUGE]. The distribution of
+ pseudorandom numbers should be uniform. */
I suspect this is wrong. DOesn't it return a value in the range
[- (GFC_INTEGER_4_HUGE + 1), GFC_INTEGER_4_HUGE] ?
+void prefix(random_r4) (GFC_REAL_4 *x)
+{
+
+ *x = (GFC_REAL_4) kiss_random_kernel();
+ *x = ((*x < 0) ? - *x : *x) / ((GFC_REAL_4) (GFC_INTEGER_4_HUGE) + 1.);
+}
This is wrong. (-x == x && x < 0) when x = 1u<<31.
Also ((GFC_REAL_4) (GFC_INTEGER_4_HUGE) + 1.) == GFC_INTEGER_4_HUGE
because of limited precision, so it can return 1.0. I'd prefer it if you
used/copied the existing routines to do this.
These also return in the range [0, 1], but that can be fixed by iterating
until we generate a value <1.0.
Please add a comment saying why we #if 0'd the existing implementation. ie.
randomness of values depends on seed quality, get/put don't work properly,
mention PR15619.
You also seem to have included the remnants of a previous patch, and some
debugging output.
Paul
More information about the Gcc-patches
mailing list