Enables traps/exceptions on common floating point errors. This option may not work on certain systems or only a subset of exceptions may be trapable.


#include "petscsys.h"  
PetscErrorCode PetscSetFPTrap(PetscFPTrap flag)

Not Collective

Input Parameter#

  • flag - values are

    PETSC_FP_TRAP_OFF   - do not trap any exceptions
    PETSC_FP_TRAP_ON - all exceptions that are possible on the system except underflow
    PETSC_FP_TRAP_INDIV - integer divide by zero
    PETSC_FP_TRAP_FLTOPERR - improper argument to function, for example with real numbers, the square root of a negative number
    PETSC_FP_TRAP_FLTOVF - overflow
    PETSC_FP_TRAP_FLTUND - underflow - not trapped by default on most systems
    PETSC_FP_TRAP_FLTDIV - floating point divide by zero
    PETSC_FP_TRAP_FLTINEX - inexact floating point result

Options Database Key#

  • -fp_trap <off,on> - turn on or off trapping of floating point exceptions


Preferred usage is PetscFPTrapPush() and PetscFPTrapPop() instead of this routine

Currently only PETSC_FP_TRAP_OFF and PETSC_FP_TRAP_ON are handled. All others are treated as PETSC_FP_TRAP_ON.

The values are bit values and may be |ed together in the function call

On systems that support it this routine causes floating point overflow, divide-by-zero, and invalid-operand (e.g., a NaN), but not underflow, to cause a message to be printed and the program to exit.

On many common systems, the floating point exception state is not preserved from the location where the trap occurred through to the signal handler. In this case, the signal handler will just say that an unknown floating point exception occurred and which function it occurred in. If you run with -fp_trap in a debugger, it will break on the line where the error occurred. On systems that support C99 floating point exception handling You can check which exception occurred using fetestexcept(FE_ALL_EXCEPT). See fenv.h (usually at /usr/include/bits/fenv.h) for the enum values on your system.

See Also#

PetscFPTrapPush(), PetscFPTrapPop(), PetscDetermineInitialFPTrap()





Edit on GitLab

Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages