Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Getting Nan

Mahesh_K_
Beginner
812 Views

Hi,

I'm getting NaN as answer for expressions like below

MN1=WTAP/( SQRT(GC*GAMA1/R1)*(1.0+(GAMA1-1.0)/2.0*
     &    MN1**2.0)**((GAMA1+1.0)/(2.0*(1.0-GAMA1))) )

All are real variables and they have real values.

When I simplify the expression , it gives the correct answer. But then I am getting Nan as answer for a another expression. Then I have to simplify it also. 

Please help me.

Thank you. 

Intel visual Fortran Compiler 

 

0 Kudos
3 Replies
andrew_4619
Honored Contributor III
812 Views

Well if you get NAN for that expression i would expect you will have:

a) sqrt of a negative number

b) division by zero

c) or maybe a real underflow/overflow

If you simplified it correctly and used the same values you would still get a NAN at some intermediate step for the first 2 cases so I would check that carefully. Maybe the order of the expression gives and overflow at some intermediate step in the evaluation? I would suggest you examine the value in your test case in the sequence the brackets dictate the evaluation.

GC, R1 or Gamma being zero will give a NAN as will Gamma=1

0 Kudos
TimP
Honored Contributor III
812 Views

Without a working reproducer, I don't think a definitive comment can be made, with or without the background of a former aerodynamicist.

To begin with, we would need to see data types, initial values, ....

Among the unnecessary opportunities you leave for varying compiler translations are the use of **2.0 where you may mean **2 (ifort will assume that) and /2.0 in place of *.5 (ifort will not do that when safe options are used, even though this is a safe replacement).

0 Kudos
mecej4
Honored Contributor III
812 Views

You cannot expect  a definite resolution of the problem when you have displayed only one line of code, and you say that changing that line of code causes "another expression", which you have not shown, to give an incorrect answer.  Nor have you stated what your "simplification" involved.

I note that MN1 (Mach number?) appears on both sides of the assignment statement. Is this statement placed inside an iteration block? How is MN1 initialized? What compiler options did you use? Could the value of MN1 be zero when it got used on the right hand side?

As was suggested, examine all the variables used in each expression using a debugger, or insert PRINT statements just before the statement(s) that give you NaNs. 

0 Kudos
Reply