float_control
Visual Studio 2010
Specifies floating-point behavior for a function.
float_control( value,setting [push] | push | pop )
You cannot turn float_control precise off when except is on. Similarly, precise cannot be turned off when fenv_access is on. To go from strict model to a fast model with the float_control pragma, use the following code:
#pragma float_control(except, off) #pragma fenv_access(off) #pragma float_control(precise, off) // The following line is needed on Itanium processors #pragma fp_contract(on)
To go from fast model to a strict model with the float_control pragma, use the following code:
#pragma float_control(precise, on) #pragma fenv_access(on) #pragma float_control(except, on) // The following line is needed on Itanium processors. #pragma fp_contract(off)
Other floating-point pragmas include:
The following sample shows how to catch an overflow floating-point exception by using pragma float_control.
// pragma_directive_float_control.cpp
// compile with: /EHa
#include <stdio.h>
#include <float.h>
double func( ) {
return 1.1e75;
}
#pragma float_control (except,on)
int main( ) {
float u[1];
unsigned int currentControl;
errno_t err;
err = _controlfp_s(¤tControl, ~_EM_OVERFLOW, _MCW_EM);
if (err != 0)
printf_s("_controlfp_s failed!\n");
try {
u[0] = func();
printf_s ("Fail");
return(1);
}
catch (...) {
printf_s ("Pass");
return(0);
}
}
Pass