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

Catch overflow

jq2000
Beginner
506 Views
Fortran seems to have no equivalence of Try, Throw and Catch of C++. How to catch overflow and handle it gracefully?
I tried to set "Float Point Exception Handling" to "3*" in Developer Studio Project Settings and hope to pass the overflow value to next function to handle, but it did not help. Overflow was caught by upper lever VC++ component. I hope to catch it locally.
0 Kudos
4 Replies
james1
Beginner
506 Views
With that setting you can use SIGNALQQ to define an exception handler, using SIG$FPE as the interrupt type.

James
0 Kudos
jq2000
Beginner
506 Views
Thank for your guide.
It seems that I can't use user function to handle overflow based on online documentation of "Handling Floating-Point Exceptions", " The drawback of writing your own routine is that your exception-handling routine cannot return to the process that caused the exception. This is because when your exception-handling routine is called, the floating-point processor is in an error condition, and if your routine returns, the processor is in the same state, which will cause a system termination. Your exception-handling routine can therefore either branch to another separate program unit or exit (after saving your program state and printing an appropriate message). You cannot return to a different statement in the program unit that caused the exception-handling routine, because a global GOTO does not exist, and you cannot reset the status word in the floating-point processor."

I tried to use "CALL CLEARSTATUSFPQQ()" to avoid catching overflow by upper level C++ component. But it did not work.

Following is part of overflow Fortran sample code. Please give suggestion.

ERR = SET(eNM01N25,lF00,lF00.VAL(NINT(expr(1.0))),expr(10.0**isb
*ad(expr(2.27-53.668/is0(isbad(expr(56.499+aT)))))))

Note that 10.0**isbad(...) is overflow because isbad()=1.0E+12. SET, expr, isbad, is0 are all user C functions. Fortran source code is generated automatically by a "Translator" to convert a plain text file.
I am looking for a generic method to convert any overflow results of "A*B" and "A**B" operations to a valid value 1.0+E12.
0 Kudos
james1
Beginner
506 Views
If this isn't a global concern in your code but rather an isolated expression here and there, you might go ahead and allow the default behavior where floating point overflows go to infinity, and in your expression use MIN(1.E12,suspect expression) to do this sort of clamping.

James
0 Kudos
Intel_C_Intel
Employee
506 Views
We use this code (in C) to trap FP errors in Fortran. When an FP error is trapped, it calls a Fortran routine, and then continues the Fortran execution from where the error occurred.


I hope this helps, you will need to modify it to suit your own situation.

All the best,
Eddie
0 Kudos
Reply