I’ve stumbled across either a problem with _controlfp_s (Visual Studio 2008), or my understanding of it. I thought the first out parameter returned the control flags before changes of the other parameters are applied. Seems it returns the flags after the change.
So, I thought the correct way to use it was like this:
// Chop rounding unsigned int old; _controlfp_s(&old, _RC_CHOP, _MCW_RC); // Do chopped math // Restore unsigned int unused; _controlfp_s(&unused, old, _MCW_RC);
Unfortunately I need to do this:
// Save unsigned int old1; _controlfp_s(&old1, 0, 0); // Chop rounding unsigned int old2; _controlfp_s(&old2, _RC_CHOP, _MCW_RC); // Do chopped math // Restore unsigned int unused; _controlfp_s(&unused, old1, _MCW_RC);
Have I missed something? Seems pretty stupid to have to do this.
btw: I’ve reported this to MS who said they couldn’t understand it and suggested I provide a video showing the problem. Yeah right.
Brad
According to MSDN:
(emphasis mine) So the way to reliably store the current control word is the second method you’ve written (the one you already found worked). If you’re modifying the control word, then you won’t be passing 0 for the mask, and per the function documentation it will not retrieve the current control word.