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

NaN appearing

Sirat_S_
Beginner
452 Views

Hi

I am running a program with several computations in a loop. I am getting NaN after a lot many computations. To get clean data free of NaN i made the program stop at first appearance of NaN. I got a breakpoint and what i see is an overflow. Earlier, when i had not induced any such breakpoint, as i went through the data file obtained, i saw NaN values among many normal data. Secondly, despite appearance of NaN the computation went on with number data appearing between NaN values. From this pattern should i assume that i should assign these variables to real(16) rather than real(8)?

please tell me the way out.

Shah

0 Kudos
4 Replies
andrew_4619
Honored Contributor II
452 Views

Real(16) will make things really slow. The NaN are usually caused by division by zero, You need to look improvements to the algorithms being used to trap/prevent this.

 

0 Kudos
TimP
Honored Contributor III
452 Views

NaN could be produced by infinity (overflow) times 0, as well as 0/0.

0 Kudos
Sirat_S_
Beginner
452 Views

thank u much Andrew.

its about the algorithm itself. i thought whether the bytes for the numbers just are not enough.

 

Shah

0 Kudos
Arjen_Markus
Honored Contributor I
452 Views

NaN and Infinity specifically make it possible for a program to continue. With these special numbers any arithmetic operation has a result.

Of course, NaNs are usually an indication that something is not working as expected and your mentioning overflows probably means that your calculation is unstable. Rather than using real numbers with a larger range (REAL(16) would do that) you should analyse why the numbers are getting so big. As we do not know anything about your algorithm we cannot say much about the possible causes.

0 Kudos
Reply