Search code examples
fortranfloatingintel-fortrantraceback

The meanings of "floating invalid" from ifort compiler


I use intel's ifort compiler for my Fortran code.

Sometimes I get an error during running:

forrtl: error (65): floating invalid

The compiler does not give the exact "invalid" reason. To my understanding, does this suggest one of the following?

  1. Underflow, which means too close to 0, e.g. 1e-30.
  2. Overflow, which means too large, e.g. infinity/-infinity, divide by zero.
  3. NaN.

This is useful because I can use if statement to check which one of these cases actually happened.

Beside, I'm using -g -traceback option for debugging. Is there an option which gives more details?


Solution

  • The Intel Fortran compiler generally uses IEEE arithmetic. The "floating invalid" message is a result of an unhandled IEEE exception of an invalid operation.

    Underflow and overflow are not treated as invalid operations (note that dividing zero by itself, or an infinity by another infinity are invalid, not overflowing). In basic terms, an invalid operation is one where, mathematically, the operand is not in the domain of the operator. Not just those two examples mentioned before, but things like taking the square root or log of a negative real number. Or using NaNs inappropriately.

    The Intel compiler has supported Fortran 2003's IEEE features for some time. You can use these for fine trapping of exceptions. The compile-time option fpe controls how the compiler responds to exceptions.