LCOV - code coverage report
Current view: top level - include/utils - fpe_disabler.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 8 8 100.0 %
Date: 2025-08-19 19:27:09 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_FPE_DISABLER_H
      21             : #define LIBMESH_FPE_DISABLER_H
      22             : 
      23             : 
      24             : // Local includes
      25             : #include "libmesh/libmesh_common.h"
      26             : 
      27             : // C++ includes
      28             : #include <cfenv>
      29             : 
      30             : namespace libMesh
      31             : {
      32             : 
      33             : /**
      34             :  * The \p FPEDisabler class puts Floating-Point Exception (FPE)
      35             :  * trapping on hold during its lifetime, restoring the FE environment
      36             :  * upon destruction.  This allows code to ignore known/expected FPE
      37             :  * sources, e.g. to work around a bug in HDF5 1.14.3 or to test for
      38             :  * errors in a more sophisticated way and throw a C++ exception
      39             :  * instead.
      40             :  *
      41             :  * FE environment changes should not be made during the lifetime of
      42             :  * this object, as they will not be preserved when the destructor
      43             :  * restores the original environment.
      44             :  *
      45             :  * \author Roy Stogner
      46             :  * \date 2024
      47             :  * \brief Temporarily disables Floating-Point Exception (FPE) trapping
      48             :  */
      49             : struct FPEDisabler
      50             : {
      51         719 :   FPEDisabler()
      52       15163 :   {
      53       15163 :     std::feholdexcept(&old_env);
      54         719 :   }
      55             : 
      56         719 :   ~FPEDisabler()
      57         719 :   {
      58       15163 :     std::fesetenv(&old_env);
      59       14441 :   }
      60             : 
      61             :   std::fenv_t old_env;
      62             : };
      63             : 
      64             : } // namespace libMesh
      65             : 
      66             : #endif // LIBMESH_PERFLOG_H

Generated by: LCOV version 1.14