https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99740
Bug ID: 99740 Summary: floating point exception in rand() in gfortran Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: pvoytas at gmail dot com Target Milestone: --- Possible bug in gfortran rand() function? Included code fails with IEEE divide by zero signalling. When I request a backtrace, it is from a line with "-log(rand(0))". Last output to the file for code included below is 0.183492497 on line 7372837. If I just write the rand(0) to file (not taking the log), the code finishes with no errors and the values near line 7372837 don't seem to have any weird values that would account for the error. Code runs with out errors either way if I use "call random_number(x)" to generate random numbers. Since I'm porting old code, the backward compatibility of rand(0) is needed. (note: Code compiles and runs successfully with either g77 or gfortran on Centos 6.x machine with distro default gcc) gcc -v output: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/ohpc/pub/compiler/gcc/8.3.0/libexec/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --disable-multilib --enable-languages=c,c++,fortran --prefix=/opt/ohpc/pub/compiler/gcc/8.3.0 --disable-static --enable-shared Thread model: posix gcc version 8.3.0 (GCC) Distro: Oracle Linux (7.9): uname -a gives: Linux <hostname> 5.4.17-2011.6.2.el7uek.x86_64 #2 SMP Thu Sep 3 14:09:14 PDT 2020 x86_64 x86_64 x86_64 GNU/Linux compile command: gfortran -ffpe-trap=zero -g rantest.f compiles with no errors runtime errors: Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation. Backtrace for this error: #0 0x7fc09a5113ff in ??? #1 0x7fc09ad330bc in ??? #2 0x4008cf in rantest at /home/pvoytas/ps_cp/accidentals/time_series/rantest.f:10 #3 0x400968 in main at /home/pvoytas/ps_cp/accidentals/time_series/rantest.f:13 Floating exception (core dumped) code: program rantest implicit none integer*4 i real*8 x do i=1,10000000 c call random_number(x) c write(11,*)x c write(11,*)rand(0) write(11,*)-log(rand(0)) enddo stop end