Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created June 27, 2012 17:11
Show Gist options
  • Select an option

  • Save rygorous/3005455 to your computer and use it in GitHub Desktop.

Select an option

Save rygorous/3005455 to your computer and use it in GitHub Desktop.
RAII class for when you actually need double precision. (MSVC on Win32 w/out /arch:SSE2)
// header
// RAII class. For use in 32-bit processes compiled without /arch:SSE2 - for
// when you actually need double precision. (D3D and GL like to set x87
// precision to single, which means the only thing you get out of doubles is
// the higher exponent range)
class DoublePrecisionContext
{
unsigned int oldfp;
public:
DoublePrecisionContext();
~DoublePrecisionContext();
};
// impl
#include <float.h>
DoublePrecisionContext::DoublePrecisionContext()
{
unsigned int oldfp;
_controlfp_s(&oldfp, _PC_53, _MCW_PC);
}
DoublePrecisionContext::~DoublePrecisionContext()
{
_controlfp_s(&oldfp, oldfp, _MCW_PC);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment