|
Packit |
8dc392 |
///////////////////////////////////////////////////////////////////////////
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
|
|
Packit |
8dc392 |
// Digital Ltd. LLC
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// All rights reserved.
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
8dc392 |
// modification, are permitted provided that the following conditions are
|
|
Packit |
8dc392 |
// met:
|
|
Packit |
8dc392 |
// * Redistributions of source code must retain the above copyright
|
|
Packit |
8dc392 |
// notice, this list of conditions and the following disclaimer.
|
|
Packit |
8dc392 |
// * Redistributions in binary form must reproduce the above
|
|
Packit |
8dc392 |
// copyright notice, this list of conditions and the following disclaimer
|
|
Packit |
8dc392 |
// in the documentation and/or other materials provided with the
|
|
Packit |
8dc392 |
// distribution.
|
|
Packit |
8dc392 |
// * Neither the name of Industrial Light & Magic nor the names of
|
|
Packit |
8dc392 |
// its contributors may be used to endorse or promote products derived
|
|
Packit |
8dc392 |
// from this software without specific prior written permission.
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
8dc392 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
8dc392 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit |
8dc392 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit |
8dc392 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit |
8dc392 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
8dc392 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
8dc392 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
8dc392 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
8dc392 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
8dc392 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
///////////////////////////////////////////////////////////////////////////
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
#ifndef INCLUDED_IEXMATHFLOATEXC_H
|
|
Packit |
8dc392 |
#define INCLUDED_IEXMATHFLOATEXC_H
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
#ifndef IEXMATH_EXPORT_H
|
|
Packit |
8dc392 |
#define IEXMATH_EXPORT_H
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
#if defined(OPENEXR_DLL)
|
|
Packit |
8dc392 |
#if defined(IEX_EXPORTS)
|
|
Packit |
8dc392 |
#define IEXMATH_EXPORT __declspec(dllexport)
|
|
Packit |
8dc392 |
#else
|
|
Packit |
8dc392 |
#define IEXMATH_EXPORT __declspec(dllimport)
|
|
Packit |
8dc392 |
#endif
|
|
Packit |
8dc392 |
#define IEXMATH_EXPORT_CONST
|
|
Packit |
8dc392 |
#else
|
|
Packit |
8dc392 |
#define IEXMATH_EXPORT
|
|
Packit |
8dc392 |
#define IEXMATH_EXPORT_CONST const
|
|
Packit |
8dc392 |
#endif
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
#endif
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
#include "IexNamespace.h"
|
|
Packit |
8dc392 |
#include "IexMathExc.h"
|
|
Packit |
8dc392 |
//#include <IexBaseExc.h>
|
|
Packit |
8dc392 |
#include "IexMathIeeeExc.h"
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
IEX_INTERNAL_NAMESPACE_HEADER_ENTER
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
//-------------------------------------------------------------
|
|
Packit |
8dc392 |
// Function mathExcOn() defines which floating point exceptions
|
|
Packit |
8dc392 |
// will be trapped and converted to C++ exceptions.
|
|
Packit |
8dc392 |
//-------------------------------------------------------------
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
IEXMATH_EXPORT
|
|
Packit |
8dc392 |
void mathExcOn (int when = (IEEE_OVERFLOW | IEEE_DIVZERO | IEEE_INVALID));
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
//----------------------------------------------------------------------
|
|
Packit |
8dc392 |
// Function getMathExcOn() tells you for which floating point exceptions
|
|
Packit |
8dc392 |
// trapping and conversion to C++ exceptions is currently enabled.
|
|
Packit |
8dc392 |
//----------------------------------------------------------------------
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
IEXMATH_EXPORT
|
|
Packit |
8dc392 |
int getMathExcOn();
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
//------------------------------------------------------------------------
|
|
Packit |
8dc392 |
// A classs that temporarily sets floating point exception trapping
|
|
Packit |
8dc392 |
// and conversion, and later restores the previous settings.
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// Example:
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// float
|
|
Packit |
8dc392 |
// trickyComputation (float x)
|
|
Packit |
8dc392 |
// {
|
|
Packit |
8dc392 |
// MathExcOn meo (0); // temporarily disable floating
|
|
Packit |
8dc392 |
// // point exception trapping
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// float result = ...; // computation which may cause
|
|
Packit |
8dc392 |
// // floating point exceptions
|
|
Packit |
8dc392 |
//
|
|
Packit |
8dc392 |
// return result; // destruction of meo restores
|
|
Packit |
8dc392 |
// } // the program's previous floating
|
|
Packit |
8dc392 |
// // point exception settings
|
|
Packit |
8dc392 |
//------------------------------------------------------------------------
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
class IEXMATH_EXPORT MathExcOn
|
|
Packit |
8dc392 |
{
|
|
Packit |
8dc392 |
public:
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
MathExcOn (int when)
|
|
Packit |
8dc392 |
:
|
|
Packit |
8dc392 |
_changed (false)
|
|
Packit |
8dc392 |
{
|
|
Packit |
8dc392 |
_saved = getMathExcOn();
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
if (_saved != when)
|
|
Packit |
8dc392 |
{
|
|
Packit |
8dc392 |
_changed = true;
|
|
Packit |
8dc392 |
mathExcOn (when);
|
|
Packit |
8dc392 |
}
|
|
Packit |
8dc392 |
}
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
~MathExcOn ()
|
|
Packit |
8dc392 |
{
|
|
Packit |
8dc392 |
if (_changed)
|
|
Packit |
8dc392 |
mathExcOn (_saved);
|
|
Packit |
8dc392 |
}
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
// It is possible for functions to set the exception registers
|
|
Packit |
8dc392 |
// yet not trigger a SIGFPE. Specifically, the implementation
|
|
Packit |
8dc392 |
// of pow(x, y) we're using can generates a NaN from a negative x
|
|
Packit |
8dc392 |
// and fractional y but a SIGFPE is not generated.
|
|
Packit |
8dc392 |
// This function examimes the exception registers and calls the
|
|
Packit |
8dc392 |
// fpHandler if those registers modulo the exception mask are set.
|
|
Packit |
8dc392 |
// It should be called wherever this class is commonly used where it has
|
|
Packit |
8dc392 |
// been found that certain floating point exceptions are not being thrown.
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
void handleOutstandingExceptions();
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
private:
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
bool _changed;
|
|
Packit |
8dc392 |
int _saved;
|
|
Packit |
8dc392 |
};
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
IEX_INTERNAL_NAMESPACE_HEADER_EXIT
|
|
Packit |
8dc392 |
|
|
Packit |
8dc392 |
#endif
|