[Bug libfortran/99740] floating point exception in rand() in gfortran

2021-03-29 Thread pvoytas at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99740

--- Comment #5 from Paul A. Voytas  ---
I understand random_number() is much better--which is great and I'll use it
going forward. I was just trying to not have to recode a lot in cases where I
used rand() because it was good enough. I certainly wouldn't expect bit
equivalent behavior, this just seemed beyond that--since it was included for
backwards compatibility but doesn't quite seem to be functionally so. Thanks
for your time looking into it.

[Bug libfortran/99740] floating point exception in rand() in gfortran

2021-03-25 Thread pvoytas at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99740

--- Comment #3 from Paul A. Voytas  ---
I see what you mean--if i test for rand(0)=0.d0 I do get hist with gfortran on
the EL7 machine. 

But it seems like there must still be something different from older versions.
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 CentOS6
with g77 when I run the above code I get no errors--even with 10x more
attempts--and the test for rand(0)=0.d0 never is true. On that same CentOS6
machine with gfortran, code does show rand(0)=0.d0 cases (and the -log(rand(0))
returns +Infinity.

[Bug libfortran/99740] New: floating point exception in rand() in gfortran

2021-03-23 Thread pvoytas at gmail dot com via Gcc-bugs
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  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,1000
c   call random_number(x)
c   write(11,*)x
c   write(11,*)rand(0)
   write(11,*)-log(rand(0))
  enddo
  stop
  end