From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4D84C385802D; Thu, 25 Mar 2021 17:17:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D84C385802D From: "sgk at troutmask dot apl.washington.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/99740] floating point exception in rand() in gfortran Date: Thu, 25 Mar 2021 17:17:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Mar 2021 17:17:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99740 --- Comment #4 from Steve Kargl -= -- On Thu, Mar 25, 2021 at 12:52:53PM +0000, pvoytas at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99740 >=20 > --- Comment #3 from Paul A. Voytas --- > I see what you mean--if i test for rand(0)=3D0.d0 I do get hist with gfor= tran on > the EL7 machine.=20 >=20 > But it seems like there must still be something different from older vers= ions. > The info pages for rand() say "between 0 and 1" which I always took to be > exclusive of the endpoints (of course there's machine precision). On Cent= OS6 > with g77 when I run the above code I get no errors--even with 10x more > attempts--and the test for rand(0)=3D0.d0 never is true. On that same Cen= tOS6 > machine with gfortran, code does show rand(0)=3D0.d0 cases (and the -log(= rand(0)) > returns +Infinity. >=20 g77 has not been supported for nearly 1.5 decades (gcc-3.4.6 released on 6 Mar 2006). gfortran tries to provide some level of API compatibility with g77. I believe there has never been a commitment to provide bit-for-bit compatibility (especially for something like rand()). Having now looked at g77's rand() implementation, I see that it is a wrapper around the libc routine by the same name rand(3). The quality of implementation of libc's rand(3) certainly=20 varies across operating systems. gfortran's rand() implements the classic Park and Miller LCG RNG with an internal range of [0, 2**31-1), which yields a random number in [0., 1.). You really want to switch to using random_number(). The internal generator used in it has an enormous period and very good statistical quality, and random_number() is specified by the actual Fortran standard.=