当您使用浮点数( 、float、double类型long double)进行操作时,是否可以检测到精度损失?说:
template< typename F >
F const sum(F const & a, F const & b)
{
F const sum_(a + b);
// The loss of precision must be detected (here or one line above) if some fraction bit is lost due to rounding
return sum_;
}
Run Code Online (Sandbox Code Playgroud)
特别感兴趣的是x87 FPU 出现在目标架构上,但例程不干预asm纯 C++ 代码的情况。如果有的话,也接受C++11或gnu++11特定功能。