forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unexpected double precision when compiling for x86

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Sun Oct 31, 2021 12:18 pm    Post subject: Unexpected double precision when compiling for x86 Reply with quote

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.

Code:
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:

Code:
        1.000000000000000        0.100000001490116
        1.000000000000000        0.100000001490116


The output from FTN95 32-bit:

Code:
        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:

Code:
    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

Code:
x = cmplx(1.0d0,h)


instead of

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


The variable h had been declared double precision.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Mon Nov 01, 2021 7:52 am    Post subject: Reply with quote

mecej4

Thank you for the feedback. I have made a note of your request.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Nov 16, 2021 2:50 pm    Post subject: Reply with quote

In future a warning will be provided when the arguments of CMPLX are not single precision.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group