两个相等的计算不返回相同的结果

two equal calculations not returning the same result

本文关键字:计算 返回 结果 两个      更新时间:2023-10-16

我得到了两个不同的.cpp文件,两个相等的计算。但是它们不返回相同的结果吗?

一个代码

double theta = (double)maxLoc.y/angleBins*CV_PI;
std::cout << theta << " " << abs(sin(theta)) << std::endl;

一个结果

1.53589 0.999391

B 代码

double theta = (double)maxLoc.y / angleBins * CV_PI;
std::cout << theta << " " << abs(sin(theta)) << std::endl;

B 结果

1.53589 0

您可能在第二个代码片段中从 C 调用 abs 函数,该代码片段将int作为参数。在两个代码片段(以及正确的标头#include<cmath>)中使用std::abs将解决问题。