libcruft-util/debug/fpe_win32.cpp

72 lines
1.4 KiB
C++

#include "./fpe.hpp"
#undef __STRICT_ANSI__
#include <float.h>
//#pragma fenv_access (on)
using cruft::debug::fpe::scoped_reset;
///////////////////////////////////////////////////////////////////////////////
void
cruft::debug::fpe::enable (void)
{
unsigned int current;
(void)current;
_controlfp_s (&current, _MCW_EM, _EM_INVALID | _EM_ZERODIVIDE);
}
//-----------------------------------------------------------------------------
void
cruft::debug::fpe::disable (void)
{
unsigned int current;
(void)current;
_controlfp_s (&current, 0, _EM_INVALID | _EM_ZERODIVIDE);
}
//-----------------------------------------------------------------------------
bool cruft::debug::fpe::value (void)
{
unsigned current;
_controlfp_s (&current, _EM_INVALID, 0);
return current;
}
//-----------------------------------------------------------------------------
bool cruft::debug::fpe::value (bool val)
{
if (val)
enable ();
else
disable ();
return val;
}
///////////////////////////////////////////////////////////////////////////////
scoped_reset::scoped_reset ()
: m_prev (value ())
{ }
//-----------------------------------------------------------------------------
scoped_reset::scoped_reset (bool _value)
: scoped_reset ()
{
value (_value);
}
//-----------------------------------------------------------------------------
scoped_reset::~scoped_reset ()
{
value (m_prev);
}