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

Detecting NaNs

AONym
New Contributor II
779 Views
I want my Fortran pgm to cause an exception, and have the debugger get control, when a real variable is set to NaN or infinity. I have fpe:0 in the command line, and I set the FP control word using



CALL GETCONTROLFPQQ (controlword)

controlword=IAND(controlword,INOT(FPCW$INVALID))

CALL SETCONTROLFPQQ (controlword)

testNaN=x'7FF8000000000001' ! signalling NaN

ftol=testNaN

xtol=testNaN+1d0



testNaN, ftol and xtol are declared REAL(8).



But I still don't get an exception on any of the last 3 lines.



What do I need to do to get these exceptions?
0 Kudos
7 Replies
Steven_L_Intel1
Employee
779 Views
Did you compile with /fpe:0 specified?
0 Kudos
AONym
New Contributor II
780 Views
Yes. I both had fpe:0 in the command line, and the modification of the floating control word in the pgm.

FWIW, this is a mixed C++ - Fortran pgm, with the C++ the "main project" and the Fortran a library.
0 Kudos
g_f_thomas
Beginner
780 Views
Irrespective of /fpe:n, you're overriding it to allow NaN's to be generated and thenyou want the debugger to halt when one is produced. You'll have to place a breakpoint when one occurs for the debugger to catch this since it's not a bug by design. BTW, is controlword of type integer(2)?
HTH,
Gerry T.
0 Kudos
AONym
New Contributor II
780 Views



g.f.thomas wrote:

You'll have to place a breakpoint when one occurs for the debugger to catch this since it's not a bug by design. BTW, is controlword of type integer(2)?
HTH,
Gerry T.









Yes, controlWord is declared INTEGER(2), though that should not matter as long as it's >=2 bytes in size.



I want the debugger to stop at the time the Nan or infinity is generated. Therefore I can't place a breakpoint, because I don't know where to put it. At the end of a long computation, a result is displayed as NaN; the question is, where in that computation was the initial NaN generated?
0 Kudos
g_f_thomas
Beginner
780 Views
Use /fpe:0 in conjunction with traceback.
0 Kudos
AONym
New Contributor II
780 Views



g.f.thomas wrote:

Use /fpe:0 in conjunction with traceback.





As I said, I am using fpe:0. I also have traceback enabled. I do not get debugger control when a NaN appears.
0 Kudos
William_H_Intel3
Employee
780 Views

In the code snippet you posted, there is nothing to consume the result of the addition. If that is the real code you have, try adding a print statement to actually use the value. I'm just guessing the compiler may have thrown away the operation that would trip the exception since the result is never used.

Hope this is helpful...Bill

0 Kudos
Reply