我有以下代码进行双重比较。为什么我在执行时变得不平等?
#include <iostream>
#include <cmath>
#include <limits>
bool AreDoubleSame(double dFirstVal, double dSecondVal)
{
return std::fabs(dFirstVal - dSecondVal) < std::numeric_limits<double>::epsilon();
}
int main()
{
double dFirstDouble = 11.304;
double dSecondDouble = 11.3043;
if(AreDoubleSame(dFirstDouble , dSecondDouble ) )
{
std::cout << "equal" << std::endl;
}
else
{
std::cout << "not equal" << std::endl;
}
}