HP-UX Floating-Point Guide

106 Chapter 4
HP-UX Math Libraries on HP 9000 Systems
Math Library Basics
NOTE The C9X draft standard, the proposed new C standard, does not require
math functions to set errno. You will need to test for errno only if your
program must conform strictly to C89 or XPG4.2.
Handling Invalid Operation Exceptions (C
and Fortran)
The exception condition that indicates an invalid argument to a math
library function is the invalid operation condition. (See “Exception
Conditions” on page 53 for more information.)
If you do not enable a trap for invalid operations, all that happens in the
case of an invalid argument is that the invalid operation exception flag in
the status register is set and the default result is returned. You can
retrieve the value of the exception flags by calling the fetestexcept
routine, described in “Exception Bits” on page 132.
You can also enable an exception trap for invalid operations in any of
several ways:
By compiling with the option +FPV, which enables the invalid
operation trap
By calling the fesettrapenable routine with the argument
FE_INVALID, which enables the invalid operation trap
(HP Fortran 90) By compiling with the option +fp_exception,
which enables traps for invalid operation, overflow, underflow, and
division by zero.
(HP FORTRAN/9000) By compiling with the option +T, which enables
traps for invalid operation, overflow, underflow, and division by zero.
(If your program contains an ON EXTERNAL ERROR statement, you
must use this option.)
See Chapter 5 and Chapter 6 for information about all of these methods.
Math Library Error Handling for Fortran
If a Fortran intrinsic function encounters an invalid argument, it returns
a default result, just as a C function does. The default result depends on
both the function and the nature of the argument. For example, a
negative argument to the DLOG function causes it to return a NaN value.