Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

DOUBLE COMPLEX variable returns NaN

Feby_A_
Beginner
142 Views

Hi!

I am using Intel Compiler 17.0 Update 2 with Visual Studio 2013 to compile a FORTRAN code. I am supposed to get a complex number after the compute process. However the real part of the variable returns an NaN.

To verify that there is no division by zero I did the same compute in the MATLAB environment, and it promptly returned the exepected complex number.

I have included a MWE for the same. Could someone throw light on what the issue is?

 

program complx1
    implicit none
    double complex :: dc
    dc = -(-(((1.00001489783669D0*1.1D0**2.0D0+&
(2.0D0*0.0D0*0.0D0+2.0D0*0.0D0*0.0D0)*1.1D0+1.00001374871743D0*0.0D0**2.0D0&
+2.0D0*0.0D0*0.0D0*0.0D0+1.00001374871743D0*0.0D0**2.0D0)*474615.661905876D0&
+3777440278.20392D0)*1.10002331748149D0**(5.0D0/3.0D0)&
-3777440278.20392D0*1.10002331748149D0**(2.0D0/3.0D0))*(-(1.0D0/2.0D0*3777440278.20392D0&
-1.0D0/2.0D0*162834746.546865D0/1.10002331748149D0)*8.43301084637337D0&
-1.0D0/2.0D0*474615.661905876D0*3.21004552381726D0)**((1.0D0&
-0.710000000000000D0)/0.710000000000000D0)*(1.0D0&
-0.710000000000000D0)/0.710000000000000D0*(1.0D0/2.0D0*3777440278.20392D0&
-1.0D0/2.0D0*162834746.546865D0/1.10002331748149D0)&
*0.999985102385248D0/(-(1.0D0/2.0D0*3777440278.20392D0&
-1.0D0/2.0D0*162834746.546865D0/1.10002331748149D0)*8.43301084637337D0&
-1.0D0/2.0D0*474615.661905876D0*3.21004552381726D0)&
+1.10002331748149D0**(5.0D0/3.0D0)*0.999985102385248D0*589000000000.000D0&
-1.0D0/3.0D0*1.10002331748149D0*5890000000.00000D0*((-1.0D0/3.0D0*3.21004552381726D0&
+1.00001489783669D0*1.1D0**2.0D0+(2.0D0*0.0D0*0.0D0+2.0D0*0.0D0*0.0D0)*1.1D0&
+1.00001374871743D0*0.0D0**2.0D0+2.0D0*0.0D0*0.0D0*0.0D0&
+1.00001374871743D0*0.0D0**2.0D0)*0.999985102385248D0+1.21000000000000D0&
-3.0D0*1.1D0**2.0D0))/1.10002331748149D0**(5.0D0/3.0D0)

    write (*,*) dc
    write (*,'(F0.0)') dc
    write (*,'(F0.0,A,F0.0)') dble(dc), ' + i ' , aimag(dc)
end program complx1

Here is a screengrab same computation performed on MATLAB.

MATLAB-Screengrab

0 Kudos
6 Replies
Arjen_Markus
Valued Contributor III
142 Views

I got NaN with Intel Fortran 2018 as well, but when I tried to compile the program with gfortran I got the compile time error:


     1.10002331748149D0**(2.0D0/3.0D0))*(-(1.0D0/2.0D0*3777440278.20392D0-1.0D0/2.0D0*&
                                        1
Error: Raising a negative REAL at (1) to a REAL power is prohibited

Somewhere in this complex (no pun intended) expression you have a negative real that is raised to a real power. I think you should make that negative real a complex number for this to work.

Feby_A_
Beginner
142 Views

That was a life saver!

A DCMPLX type conversion worked out.

I guess Intel Compiler should throw up a warning for such cases.

Thank you Markus.

Arjen_Markus
Valued Contributor III
142 Views

I think the gfortran compiler uses a different strategy for these cases than the Intel Fortran compiler: the one uses compile-time evaluation, the other does not. I have not found a flag, though, that will cause the program to stop with an understandable error message, alas. May be the limited time I put into that. I did not try any of the IEEE routines to control floating-point behaviour - that mihgt be the way to go, as this is clearly an example of the calculations that are going on in your actual program.

Steve_Lionel
Black Belt Retired Employee
142 Views
C:\Projects>ifort /fpe0 t.f90 /traceback
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.2.190 Build 20190117
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 14.15.26730.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:t.exe
-subsystem:console
-incremental:no
t.obj

C:\Projects>t.exe
forrtl: error (65): floating invalid
Image              PC                Routine            Line        Source
t.exe              00007FF6076E3239  __libm_pow_e7               0  Unknown
t.exe              00007FF6076E1AB7  __libm_pow_dispat           0  Unknown
t.exe              00007FF60769105A  MAIN__                     10  t.f90

 

Arjen_Markus
Valued Contributor III
142 Views

I knew there was some option to get this result!  I just could not find it from the description from "ifort -help"

Feby_A_
Beginner
142 Views

Thank you Steve. I learned something new. Newbie here. :)

Reply