Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development Tools (Compilers, Debuggers, Profilers & Analyzers)
- Intel® Fortran Compiler
- DOUBLE COMPLEX variable returns NaN

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

Feby_A_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-10-2019
10:43 PM

65 Views

DOUBLE COMPLEX variable returns NaN

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.

6 Replies

Highlighted
##

Arjen_Markus

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-10-2019
11:44 PM

65 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.

Highlighted
##

Feby_A_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-11-2019
12:07 AM

65 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.

Highlighted
##

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.

Arjen_Markus

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-11-2019
12:30 AM

65 Views

Highlighted
##

Steve_Lionel

Black Belt Retired Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-11-2019
05:55 AM

65 Views

Highlighted
##

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

Arjen_Markus

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-11-2019
05:57 AM

65 Views

Highlighted
##

Feby_A_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-11-2019
07:21 AM

65 Views

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

For more complete information about compiler optimizations, see our Optimization Notice.