gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfx
1617 Posts in 535 Topics by 779 Members - Latest Member: rhoronjeff@comcast.net November 27, 2022, 09:28:09 PM
*
gfx* Home | Help | Search | Login | Register | gfx
gfx
Absoft User Forum  |  Support  |  Macintosh  |  odd behavior of double precision complex numbers
gfx
gfxgfx
 

Author Topic: odd behavior of double precision complex numbers  (Read 2695 times)

mdegraef

  • Newbie
  • *
  • Posts: 8
odd behavior of double precision complex numbers
« on: November 05, 2013, 02:40:27 PM »

Hi, I noticed some odd behavior of the cmplx routine; I am simply trying to create the complex number (double precision)
with real part 0.0D0 and imaginary part Pi, using the following program:

program tester

IMPLICIT NONE

! set the single and double precision kinds
integer,parameter      :: sgl = SELECTED_REAL_KIND(p=6,r=37)   
integer,parameter      :: dbl = SELECTED_REAL_KIND(p=13,r=200)   

real(kind=dbl), parameter    :: dPi=3.141592653589793238D0
real(kind=sgl), parameter    :: sPi=3.1415926

write (*,*) 'Single precision : ', sPi
write (*,*) 'Double precision : ', dPi
write (*,*) ' '
write (*,*) 'Several attempts to create the complex number (0.0,Pi) '
write (*,*) ' '
write (*,*) 'cmplx(0.0,dPi,dbl) = ',cmplx(0.0,dPi,dbl)
write (*,*) 'cmplx(0.D0,dPi,dbl) = ',cmplx(0.D0,dPi,dbl)
write (*,*) 'dcmplx(0.0,dPi) = ',dcmplx(0.0,dPi)
write (*,*) 'dcmplx(0.D0,dPi) = ',dcmplx(0.D0,dPi)
write (*,*) ' ------ '
write (*,*) 'cmplx(0.0,sPi,sgl) = ',cmplx(0.0,sPi,sgl)
write (*,*) 'cmplx(0.D0,sPi,sgl) = ',cmplx(0.D0,sPi,sgl)
write (*,*) 'cmplx(0.0,sPi) = ',cmplx(0.0,sPi)
write (*,*) 'cmplx(0.D0,sPi) = ',cmplx(0.D0,sPi)

end program tester

The output of this program is as follows:


 Single precision :   3.14159
 Double precision :   3.14159265358979
 
 Several attempts to create the complex number (0.0,Pi)
 
 cmplx(0.0,dPi,dbl) =  (0.000000000000000,3370280550400.00)   <--------
 cmplx(0.D0,dPi,dbl) =  (0.000000000000000,3.14159265358979)
 dcmplx(0.0,dPi) =  (0.000000000000000,3370280550400.00)  <-------
 dcmplx(0.D0,dPi) =  (0.000000000000000,3.14159265358979)
  ------
 cmplx(0.0,sPi,sgl) =  (0.000000,3.14159)
 cmplx(0.D0,sPi,sgl) =  (0.000000,3.14159)
 cmplx(0.0,sPi) =  (0.000000,3.14159)
 cmplx(0.D0,sPi) =  (0.000000,3.14159)

Note the two lines with  <------ at the end; the result is wrong ...

Any idea what might be wrong/

Thanks,
Marc.

forumadmin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 333
Re: odd behavior of double precision complex numbers
« Reply #1 on: November 06, 2013, 06:57:06 AM »
Thank you for reporting this. It will be fixed in the update. As you have discovered, there are several work-arounds. Perhaps the easiest is to ensure that both arguments to CMPLX are the same KIND:

CMPLX(0.0d0, 3.1415926565897d0)

Another is to not use the CMPLX function to convert a complex constant to a complex constant. For example:

print *, (0.0d0, 3.1415926565897d0)

The normal use of CMPLX with variables is not affected by the bug you reported.
« Last Edit: November 14, 2013, 11:14:49 AM by Amy H »

Absoft User Forum  |  Support  |  Macintosh  |  odd behavior of double precision complex numbers
 

gfxgfx
gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!