Created
June 27, 2012 17:11
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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