LCOV - code coverage report
Current view: top level - include/utils - FloatingPointExceptionGuard.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 7 9 77.8 %
Date: 2025-07-17 01:28:37 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "MooseApp.h"
      13             : #include "libmesh/libmesh.h"
      14             : 
      15             : /**
      16             :  * Scope guard for starting and stopping Floating Point Exception Trapping
      17             :  */
      18             : class FloatingPointExceptionGuard
      19             : {
      20             : public:
      21             :   /**
      22             :    * Instantiation turns on FPE Trapping as long as trapping is enabled on the application. By
      23             :    * default trapping is enabled when the DEBUG symbol is defined (dbg mode), but can be overridden
      24             :    * and turned on and off for any particular simulation run.
      25             :    */
      26     3641203 :   FloatingPointExceptionGuard(const MooseApp & moose_app)
      27     3641203 :     : _trapping_enabled(moose_app.getFPTrapFlag())
      28             :   {
      29     3641203 :     if (_trapping_enabled)
      30           0 :       libMesh::enableFPE(true);
      31     3641203 :   }
      32             : 
      33             :   /**
      34             :    * Stop FPE Trapping on destruction
      35             :    */
      36     3641142 :   ~FloatingPointExceptionGuard()
      37             :   {
      38     3641142 :     if (_trapping_enabled)
      39           0 :       libMesh::enableFPE(false);
      40     3641142 :   }
      41             : 
      42             : private:
      43             :   /// Determine whether or not PFE trapping needs to be toggled off.
      44             :   const bool _trapping_enabled;
      45             : };

Generated by: LCOV version 1.14