HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IexMathFloatExc.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IEXMATHFLOATEXC_H
7 #define INCLUDED_IEXMATHFLOATEXC_H
8 
9 #include "IexExport.h"
10 #include "IexNamespace.h"
11 
12 #include "IexMathIeeeExc.h"
13 
15 
16 //-------------------------------------------------------------
17 // Function mathExcOn() defines which floating point exceptions
18 // will be trapped and converted to C++ exceptions.
19 //-------------------------------------------------------------
20 
22 void mathExcOn (int when = (IEEE_OVERFLOW | IEEE_DIVZERO | IEEE_INVALID));
23 
24 //----------------------------------------------------------------------
25 // Function getMathExcOn() tells you for which floating point exceptions
26 // trapping and conversion to C++ exceptions is currently enabled.
27 //----------------------------------------------------------------------
28 
30 int getMathExcOn ();
31 
32 //------------------------------------------------------------------------
33 // A class that temporarily sets floating point exception trapping
34 // and conversion, and later restores the previous settings.
35 //
36 // Example:
37 //
38 // float
39 // trickyComputation (float x)
40 // {
41 // MathExcOn meo (0); // temporarily disable floating
42 // // point exception trapping
43 //
44 // float result = ...; // computation which may cause
45 // // floating point exceptions
46 //
47 // return result; // destruction of meo restores
48 // } // the program's previous floating
49 // // point exception settings
50 //------------------------------------------------------------------------
51 
53 {
54 public:
55  IEX_EXPORT MathExcOn (int when);
56  IEX_EXPORT ~MathExcOn ();
57  MathExcOn (const MathExcOn&) = delete;
58  MathExcOn& operator= (const MathExcOn&) = delete;
59  MathExcOn (MathExcOn&&) = delete;
60  MathExcOn& operator= (MathExcOn&&) = delete;
61 
62  // It is possible for functions to set the exception registers
63  // yet not trigger a SIGFPE. Specifically, the implementation
64  // of pow(x, y) we're using can generates a NaN from a negative x
65  // and fractional y but a SIGFPE is not generated.
66  // This function examimes the exception registers and calls the
67  // fpHandler if those registers modulo the exception mask are set.
68  // It should be called wherever this class is commonly used where it has
69  // been found that certain floating point exceptions are not being thrown.
70 
71  IEX_EXPORT void handleOutstandingExceptions ();
72 
73 private:
74  bool _changed;
75  int _saved;
76 };
77 
79 
80 #endif
IEX_INTERNAL_NAMESPACE_HEADER_ENTER IEX_EXPORT void mathExcOn(int when=(IEEE_OVERFLOW|IEEE_DIVZERO|IEEE_INVALID))
#define IEX_EXPORT
Definition: IexExport.h:30
IEX_EXPORT int getMathExcOn()
#define IEX_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: IexNamespace.h:79
IEEE_DIVZERO
LeafData & operator=(const LeafData &)=delete
#define IEX_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: IexNamespace.h:82
IEEE_OVERFLOW
#define IEX_EXPORT_TYPE
Definition: IexExport.h:31