petsc-3.10.5 2019-03-28
Report Typos and Errors

# PetscSetFPTrap

Enables traps/exceptions on common floating point errors. This option may not work on certain machines.

### Synopsis

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

Not Collective

### Input Parameters

flag -PETSC_FP_TRAP_ON, PETSC_FP_TRAP_OFF.

### Options Database Keys

-fp_trap -Activates floating point trapping

### Description

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

### Note

On many common systems including x86 and x86-64 Linux, 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. 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.

### Caution

On certain machines, in particular the IBM rs6000, floating point trapping is VERY slow!

### See Also

PetscFPTrapPush(), PetscFPTrapPop()

### Level

advanced

### Location

src/sys/error/fp.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages