相关疑难解决方法(0)

cos返回错误的值?

我对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).

我错过了一些非常基本和简单的东西......?

c++ cmath

3
推荐指数
1
解决办法
6186
查看次数

标签 统计

c++ ×1

cmath ×1