debug/fpe: add win32 implementation

This commit is contained in:
Danny Robson 2021-05-18 06:57:29 +10:00
parent f9c298fba5
commit f1ff722085

View File

@ -0,0 +1,71 @@
#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);
}