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

Program Exception: 0.0 Raised to a Negative Integer Power

ccoroian
Beginner
1,503 Views
Problem Description:
Raising 0.0 or NaN to a negative integer power crashes the program and
produces the following error:
forrtl: severe (696): Real zero raised to negative power
Floating point exception handling is set to 3*, allowing for NaN and +/-
Infinity. Raising 0.0 to a negative real power results in Infinity, as
is to be expected. In addition, real-valued constants appear to be
converted by the compiler into integer constants, so that the statement
b**-1.0 (where b is a real) crashes as if -1.0 were an integer type.
However, the expression b**-1.2 will result in Infinity. NaN and
Infinity are valid results for my application, so this is a critical
error. This is especially true since I have found no way to trap the
exception. Below is a simple program demonstrating the error.


program main

a=0.0
b=-1.0

i=0
j=1
k=-1

! These Work
PRINT *, a**b
PRINT *, a**-1.2

! Crashes Program
PRINT *, a**-1.0

! Also Crashes Program, if Previous Line Commented Out
PRINT *, a**k



CONTINUE

END


SUBROUTINE MATHERRQQ(name, len, info, retcode)
USE DFLIB
INTEGER(2) len, retcode
CHARACTER(len) name
RECORD /MTH$E_INFO/ info

PRINT *, "Handling Math Error"

retcode=1

END SUBROUTINE



0 Kudos
2 Replies
ccoroian
Beginner
1,503 Views
Does anyone have any idea pertaining to the posted message? Any help, suggestions, or alternatives would be much appreciated.

Thank you.

Cristian C.
0 Kudos
Steven_L_Intel1
Employee
1,503 Views
Someone sent this to CVF support and I answered it from there - I didn't realize it wasn't you. Support is the best place to send questions that involve the compiler not doing what you think it should.

It's a compiler bug that occurs when the compiler is evaluating an expression at compile-time (it can do it in these cases) and the result should be an IEEE exceptional value (NaN or Inf). Instead of delivering the NaN or Inf it generates code that causes a run-time exception.

This is a difficult problem to fix, and I can't promise when a fix will appear. You'll have to use a workaround for now - one that forces the computation to be done at run-time. We apologize for the inconvenience.

Steve
0 Kudos
Reply