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

NaN

Dx
Beginner
340 Views
My Fortran code sometimes gave results as NaN (Not a number). How can I change these NaN to some kind numbers (like 1e200 or something) so that my program can continue.

Thanks
0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
340 Views

Dx,

You need to determine the underlaying cause for generating the NaN.
A frequent cause is the use of uninitialized variables.

Jim
0 Kudos
tropfen
New Contributor I
340 Views
Quoting - Dx
My Fortran code sometimes gave results as NaN (Not a number). How can I change these NaN to some kind numbers (like 1e200 or something) so that my program can continue.

Thanks
Hello Dx,

you can test for a NaN using isnan().

Frank
0 Kudos
Dx
Beginner
340 Views
Quoting - tropfen
Hello Dx,

you can test for a NaN using isnan().

Frank

Thanks for your comments. I think the reason for my seeing NaN is the the program is going to the wrong direction.
Can I overwrite the NaN with some numbers ( say 0 or 1e200 or something) so the program can go to the next step?
Thanks again.
0 Kudos
Steven_L_Intel1
Employee
340 Views
No, you can't do that. What you can try is setting the option /fpe:0 (under Fortran > Floating Point) - if a calculation in the generated code would result in a NaN, this should give an error instead. NaNs can occur other ways that this won't catch, however.
0 Kudos
Reply