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

compiler does not catch floating point exceptions properly

maeshtro
Beginner
647 Views

I have made the following program to test how the Intel fortran compiler (10.0.*) catches fp exceptions. I am running fedora 7 on a intel pentium 4.


program test_ieee_fpe
 use ifport
 implicit none
 real :: x, y, z
 integer*4 :: ir
 character*20 :: out
 x=0.
 y=1.
 z=y/x		! Division by zero
 ir=ieee_flags('get', 'exception', '', out)
 print*,'Exception raised: ', out
end program test_ieee_fpe

When I compile and run the program, no exception is raised (that is, "out" is null) . However, if I try to print (either on the creen or to a file) the value of "z", the exception "division" is triggered.


Anyway, other operations leading to fp exceptions are not got by ieee_flags, for example invalid operations such as sqrt(-1.0) or overflows.

real x
x=sqrt(-1.0)	! Invalid operation
ir=ieee_flags('get', 'exception', '', out)

x is assigned to "NaN" but "out" is NULL. The same happens when an overflow occurs.

Has anybody else experienced these problems?

Remark: If I compile with the option -fpe0, the exceptions are properly catched, but this is not the behavior I want, since I want the program to catch the exceptions and keep on running.

Best regards,

Rafa Gallego




0 Kudos
1 Reply
Steven_L_Intel1
Employee
647 Views
If you don't use the result, the computation may be optimized away.

With the default -fpe3, there is no exception to raise. The operation simply results in a NaN or Inf, etc. Operations such as SQRT will directly assign a NaN to the result for out of range arguments - again, no exception is raised.

There isn't a straightforward way I know of to have the exception, catch it, and continue from the point of the error.
0 Kudos
Reply