Silverfrost Forums

Welcome to our forums

Unexpected double precision when compiling for x86

31 Oct 2021 11:18 #28415

The intrinsic function CMPLX(x, y) should return a complex result of default kind, regardless of whether the arguments x and y are single or double precision. FTN95 /64 adheres to this expectation, but an EXE from a FTN95 32-bit compilation may give a double precision result. The following test code illustrates the issue.

program xcmplx
implicit none
integer, parameter :: dp = kind(0d0)
real(dp)    :: dx = 1d-1
complex(dp) :: x, y
!
x = cmplx(1d0, 1d-1) ! warning: expression is single precision
y = cmplx(1d0, dx)
print 10,x,y
10 format(2F25.15)
end

The output from FTN95 /64:

        1.000000000000000        0.100000001490116
        1.000000000000000        0.100000001490116

The output from FTN95 32-bit:

        1.000000000000000        0.100000001490116
        1.000000000000000        0.100000000000000

Gfortran gives the same result as FTN95 /64. If it is used with its -Wall option, Gfortran also gives a warning:

    7 | x = cmplx(1d0, 1d-1) ! warning: expression is single precision
      |          1
Warning: Conversion from REAL(8) to default-kind COMPLEX(4) at (1) might lose precision, consider using the KIND argument [-Wconversion] 

It would be useful to have FTN95 issue a similar warning.

In the larger code where the issue arose, it took quite a bit of effort to isolate the problem to the missing third argument to CMPLX, i.e., writing

x = cmplx(1.0d0,h)

instead of

x = cmplx(1.0d0,h,kind(1d0))

The variable h had been declared double precision.

1 Nov 2021 6:52 #28417

mecej4

Thank you for the feedback. I have made a note of your request.

16 Nov 2021 1:50 #28468

In future a warning will be provided when the arguments of CMPLX are not single precision.

Please login to reply.