Is there a standard way to check for Infinite and NaN in Fortran 90/95?

前端 未结 8 1186
小鲜肉
小鲜肉 2020-12-06 15:59

I\'ve been trying to find a standards-compliant way to check for Infinite and NaN values in Fortran 90/95 but it proved harder than I thought.

  • I tried to manua
8条回答
  •  感情败类
    2020-12-06 16:30

    The simple way without using the ieee_arithmatic is to do the following.

    Infinity: Define your variable infinity = HUGE(dbl_prec_var) (or, if you have it, a quad precision variable). Then you can simply check to see if your variable is infinity by if(my_var > infinity).

    NAN: This is even easier. By definition, NAN is not equal to anything, even itself. Simply compare the variable to itself: if(my_var /= my_var).

提交回复
热议问题