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


> irand(i) returns a value in the range [1,GFC_RAND_M-1].
> irand(i) - 1 is in the range [0,GFC_RAND_M-2].  So, the
> division above is in the range [0,1).

You're forgetting that real*4 has significantly less than 32 bits precision, 
so is unable to accurately represent integers of this magnitude. After 
rounding the result will in the range [0-1]

Paul


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