Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

NaN appearing

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
Highlighted
Valued Contributor II
1 View

Real(16) will make things

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
Highlighted
Black Belt
1 View

NaN could be produced by

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

0 Kudos
Highlighted
Beginner
1 View

thank u much Andrew.

thank u much Andrew.

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

 

Shah

0 Kudos
Highlighted
Valued Contributor II
1 View

NaN and Infinity specifically

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