Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neglecting NaN terms in a summation in Fortran

Tags:

nan

fortran

Is there a way to combine NaN and ordinary numbers in a different way then usually done in Fortran?

I have several summations which contains 'safe' terms, which cannot be NaN, and some other terms which can be NaN. I would like the evaluation of the expression to neglect the addends in case they are NaN.

I cannot just get rid of them multiplying them times a null factor when they are NaN as NaN x 0 gives NaN anyway. Ideas?

Thanks

like image 708
pugliam Avatar asked Dec 04 '25 07:12

pugliam


1 Answers

There is no arithmetic operation that does not propagate NaN. So ideas like multiplying by 0 will not work.

Your only solution is to miss out the NaN terms in the sum. Do that with something based on

IF (IEEE_IS_NAN(x)) 

If you are not using IEEE754 or are using an older standard of FORTRAN, then you can use

IF(x .NE. x)

which will be TRUE if and only if x is NaN.

like image 163
Bathsheba Avatar answered Dec 07 '25 15:12

Bathsheba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!