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
- From: Paul Brook <paul at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>,gcc-patches at gcc dot gnu dot org
- Date: Sun, 30 May 2004 23:10:20 +0100
- Subject: Re: [gfortran] Implement irand(), rand(), and srand() for G77 compatibility
- Organization: CodeSourcery
- References: <20040530185518.GA61701@troutmask.apl.washington.edu>
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.
> 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.
Paul