diff --git a/src/main.cpp b/src/main.cpp index cc8f8be906..7401183fea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,10 @@ #include #include +#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE) +#include +#endif + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- @@ -28,6 +32,18 @@ int main(int argc, char **argv) { MPI_Init(&argc,&argv); +// enable trapping selected floating point exceptions. +// this uses GNU extensions and is only tested on Linux +// therefore we make it depend on -D_GNU_SOURCE, too. + +#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE) + fesetenv(FE_NOMASK_ENV); + fedisableexcept(FE_ALL_EXCEPT); + feenableexcept(FE_DIVBYZERO); + feenableexcept(FE_INVALID); + feenableexcept(FE_OVERFLOW); +#endif + #ifdef LAMMPS_EXCEPTIONS try { LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD);