3

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?

francescalus
  • 30,576
  • 16
  • 61
  • 96
uPhone
  • 313
  • 4
  • 13
  • i'd suggest getting a copy of your compilers manual, or find its online documentation. note that a very similar question to yours have been asked here: https://stackoverflow.com/questions/25537187/questions-on-forrtl-error-65-floating-invalid – builder-7000 Jan 30 '19 at 04:08
  • A division by zero (of a finite nonzero number) does not signal an overflow. However, it has its own divideByZero exception. Note that the overflow definition in the IEEE 754 standard (1985, 2008, 2019) is incorrect; it should exclude exact infinities, which are not overflows in practice (I've raised an issue in the stds-754 list). – vinc17 Aug 18 '21 at 11:17

1 Answers1

3

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.

francescalus
  • 30,576
  • 16
  • 61
  • 96
  • fpe seems like a way of hiding these issues by allowing them in run-time (e.g. set them to zeros). Is this a good practice? Is there a compile option to reveal them instead of hide? – uPhone Jan 30 '19 at 15:22
  • Certain `fpe` settings force the program to halt on the first exception (which is probably what you are seeing in the case of the question). Other settings allow the program to behave according to the requirements of the program itself (using the standard intrinsic IEEE modules of F2003). In such a mode (`fpe3`, the default with current versions of ifort) exceptions can be ignored completely or selectively. "Good practice" will depend on your individual needs. – francescalus Jan 30 '19 at 15:27