John, the following program may help us get closer to the heart of the problem. It does the same calculation as before, but with values of x close to the problematic value. With versions of Gfortran on Windows that use the implementation of tanh() in the Microsoft VC RTL, such as Mingw, the last column is always zero. With Cygwin on Windows, MS WSL-1 and on Linux, we can speculate that the underlying GNU math library causes different behavior, with the last column giving either 1.00000E+00 or 0.00000E+00.
program mterr
use iso_fortran_env
implicit none
integer i,ix
real x,tnhx,f
!
write (*,*) compiler_version()
print *
print *,' x x(IEEE hex) tanh(x) 1/x - 1/tanh(x)'
print *,' ---------- -------- ----------- ---------------'
ix = Z'33DBE6F8'
do i=1,16
x = transfer(ix,x)
tnhx = tanh(x)
f = 1.0/x - 1.0/tnhx
print 10,i,x,ix,tnhx,f
ix = ix+1
end do
10 format(i2,ES15.5,2x,Z8,2ES15.5)
end program
I'd appreciate your trying this program with your Gfortran 10.x. On a Linux server in the Cloud, here is what I got:
$gfortran -std=gnu *.f95 -o main
$main
GCC version 7.1.1 20170622 (Red Hat 7.1.1-3)
x x(IEEE hex) tanh(x) 1/x - 1/tanh(x)
---------- -------- ----------- ---------------
1 1.02400E-07 33DBE6F8 1.02400E-07 1.00000E+00
2 1.02400E-07 33DBE6F9 1.02400E-07 1.00000E+00
3 1.02400E-07 33DBE6FA 1.02400E-07 0.00000E+00
4 1.02400E-07 33DBE6FB 1.02400E-07 1.00000E+00
5 1.02400E-07 33DBE6FC 1.02400E-07 1.00000E+00
6 1.02400E-07 33DBE6FD 1.02400E-07 0.00000E+00
7 1.02400E-07 33DBE6FE 1.02400E-07 1.00000E+00
8 1.02400E-07 33DBE6FF 1.02400E-07 1.00000E+00
9 1.02400E-07 33DBE700 1.02400E-07 0.00000E+00
10 1.02400E-07 33DBE701 1.02400E-07 1.00000E+00
11 1.02400E-07 33DBE702 1.02400E-07 1.00000E+00
12 1.02400E-07 33DBE703 1.02400E-07 1.00000E+00
13 1.02400E-07 33DBE704 1.02400E-07 0.00000E+00
14 1.02400E-07 33DBE705 1.02400E-07 1.00000E+00
15 1.02400E-07 33DBE706 1.02400E-07 1.00000E+00
16 1.02400E-07 33DBE707 1.02400E-07 0.00000E+00
For readers who have not been following this thread closely: FTN95 is not afflicted with this problem.