, -ffast-math / IEEE, . http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Optimize-Options.html#Optimize-Options:
-O, -Ofast, , / IEEE ISO . , , .
, -ffast-math, , .
, -ffast-math -ffinite-math-only, . http://gcc.gnu.org/wiki/FloatingPointMath, ( http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Optimize-Options.html#Optimize-Options)
[...] , , NaN + -Infs
, , -ffast-math, , NaN, , , , , isinf isnan false ( ). , .
, , NaN ( - , isinf isnan), -ffast-math, .
my_isnan ( ), . , - () ( , ), NaN , , , , std::isnan false. , , , sqrt, , NaN -1. , , .
( ) , , ++, , C- ( , , C, ++, ?).
-ffast-math my_isnan, , , , , , , .
-ffast-math -fno-finite-math-only, .
, :
#pragma, __attribute__, -ffast-math ( -ffinite-math-only -fno-finite-math-only) ( , , GCC ) . , , , NaN. , , -ffinite-math-only .
, , -ffast-math , . , ( , , William Kahan , . ). , , (. ). , , , , ,
- , . , (, , ), , -ffast-math, . , :
#include <iostream>
#include <limits>
int main() {
double d = 1.0;
double max = std::numeric_limits<double>::max();
d /= max;
d *= max;
std::cout << d << std::endl;
return 0;
}
1, , - , -ffast-math, 0.