我对cmath/math.h的标准cos函数有一个奇怪的问题.显然在某些情况下它会返回错误或简单的未定义值.
#include <cmath>
#include <iostream>
int main()
{
double foo = 8.0 * 0.19634955; // 1.5707964
double bla = std::cos(foo); // should be 0.9996242168245
std::cout << bla << std::endl; // cos returns -7.32051e-008
return 0;
}
Run Code Online (Sandbox Code Playgroud)
例如,如果cos的输入值是1.5707964,则cos返回-7.32051e-008(使用双精度时,浮点数为-4.XYZe-009).
我错过了一些非常基本和简单的东西......?