24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

call fpgets(fpstat)<br />

fpstat(fpox) = .FALSE.<br />

call fpsets(fpstat) ! resetting fpstat(fpox) to .FALSE.<br />

Sample Programs <strong>for</strong> Exception Handling<br />

/usr/lpp/xlf/samples/floating_point contains a number of sample programs to<br />

illustrate different aspects of exception handling:<br />

flttrap_handler.c and flttrap_test.f<br />

A sample exception handler that is written in C<br />

and a <strong>Fortran</strong> program that uses it.<br />

xl__ieee.F and xl__ieee.c<br />

Exception handlers that are written in <strong>Fortran</strong> and<br />

C that show how to substitute particular values <strong>for</strong><br />

operations that produce exceptions. Even when<br />

you use support code such as this, the<br />

implementation of <strong>XL</strong> <strong>Fortran</strong> exception handling<br />

does not fully support the exception-handling<br />

environment that is suggested by the IEEE<br />

floating-point standard.<br />

check_fpscr.f and postmortem.f<br />

Show how to work with the fpsets and fpgets<br />

procedures and the fpstats array.<br />

fhandler.F<br />

xl__trbk_test.f<br />

Shows a sample <strong>Fortran</strong> signal handler and<br />

demonstrates the xl__sigdump procedure.<br />

Shows how to use the xl__trbk procedure to<br />

generate a traceback listing without stopping the<br />

program.<br />

The sample programs are strictly <strong>for</strong> illustrative purposes only.<br />

Causing Exceptions <strong>for</strong> Particular Variables<br />

To mark a variable as “do not use”, you can encode a special value called a<br />

signaling NaN in it. This causes an invalid exception condition any time that<br />

variable is used in a calculation.<br />

If you use this technique, use the nans suboption of the -qfloat option, so that the<br />

program properly detects all cases where a signaling NaN is used, and one of the<br />

methods already described to generate corresponding SIGFPE or SIGTRAP<br />

signals.<br />

Notes:<br />

1. Because a signaling NaN is never generated as the result of a calculation and<br />

must be explicitly introduced to your program as a constant or in input data,<br />

you should not need to use this technique unless you deliberately use signaling<br />

NaN values in it.<br />

2. In previous <strong>XL</strong> <strong>Fortran</strong> releases, the -qfloat suboption was called spnans. In the<br />

future, use nans instead (although spnans still works, <strong>for</strong> backward<br />

compatibility).<br />

Minimizing the Per<strong>for</strong>mance Impact of Floating-Point<br />

Exception Trapping<br />

If you need to deal with floating-point exception conditions but are concerned that<br />

doing so will make your program too slow, here are some techniques that can help<br />

minimize the per<strong>for</strong>mance impact:<br />

302 <strong>XL</strong> <strong>Fortran</strong> <strong>Enterprise</strong> <strong>Edition</strong> <strong>for</strong> <strong>AIX</strong> : User’s <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!