This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gfortran] Implement irand(), rand(), and srand() for G77 compatibility
On Sun, May 30, 2004 at 11:10:20PM +0100, Paul Brook wrote:
> On Sunday 30 May 2004 19:55, Steve Kargl wrote:
> > Here is an implementation of irand(), rand(), and srand()
> > for G77 compatibility. I have bootstrapped and tested
> > gfortran on FreeBSD. The outputs from a program using
> > these functions and compiled with gfortran and g77 were
> > compared. On the FreeBSD, the outputs were essentially
> > identical.
>
> + if (x->ts.kind != gfc_default_integer_kind ())
> + return FAILURE;
>
> You should use kind_check so that a proper error message is issued.
> This doesn't match the implementation, which requires kind=4.
I just found that function while working up a patch for
"s = second()" and "call second(s)".
> > GFC_REAL_4 prefix(rand) (GFC_INTEGER_4 *i)
> > {
> > return (GFC_REAL_4) (prefix(irand)(i) - 1) / (GFC_REAL_4)(GFC_RAND_M1);
> > }
>
> This returns values in the range [0,1]
> We really need a reliable routine to convert from integer to real.
Actually, I think its worst than that.
rand_seed = GFC_RAND_A * rand_seed % GFC_RAND_M;
If GFC_RAND_A * rand_seed = GFC_RAND_M, then rand_seed becomes
0, which is really bad. We need
rand_seed = GFC_RAND_A * rand_seed % GFC_RAND_M + 1;
the range now becomes [1,GFC_RAND_M]. We then need
return (GFC_REAL_4) (prefix(irand)(i) - 1) / (GFC_REAL_4)(GFC_RAND_M);
where prefix(irand)(i) - 1 is in the range [0,GFC_RAND_M-1] and
GFC_RAND_M1 is unused.
Can you commit what I sent and I'll send a follow up to fix
these problems? My tree is fairly messed up with SECOND and
ETIME changes and I'm not sure can get a clean diff.
--
Steve