This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran] Implement irand(), rand(), and srand() for G77 compatibility


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]