ATLAS Offline Software
FPControl.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef CXXUTILS_FPCONTROL_H
14 #define CXXUTILS_FPCONTROL_H
15 
16 
17 #include "CxxUtils/bitmask.h"
18 #include <fenv.h>
19 
20 
21 namespace CxxUtils {
22 
23 
40 class FPControl
41 {
42 public:
43  // Known exception types.
44  enum class Exc
45  {
46  divbyzero = 1,
47  inexact = 2,
48  invalid = 4,
49  overflow = 8,
50  underflow = 16,
51  // Special value meaning all known exceptions.
52  // Not necessarily the same as the OR of all the above
53  // if the platform defines additional exception types beyond these.
54  all = 32,
56  };
57 
58 
64  FPControl();
65 
66 
75  ~FPControl();
76 
77 
81  void holdExceptions();
82 
83 
88  void enable (Exc exc);
89 
90 
95  void disable (Exc exc);
96 
97 
98 private:
103  int excToMask (Exc exc);
104 
106  fenv_t m_env;
107 
108  // Mask of exceptions that have been disabled.
109  int m_masked = 0;
110 };
111 
112 
113 
114 } // namespace CxxUtils
115 
116 
117 #endif // not CXXUTILS_FPCONTROL_H
ATH_BITMASK
#define ATH_BITMASK
Mark that a class enum should be treated as a bitmask.
Definition: bitmask.h:70
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
CxxUtils
Definition: aligned_vector.h:29
bitmask.h
Helpers for treating a class enum as a bitmask.