如何重现这种行为? https://isocpp.org/wiki/faq/newbie#floating-point-arith2
准确地说,在下面的代码中,参数x
和y
是相等的;它们可以等于 1.0 或任何其他值。
void foo(double x, double y)
{
double cos_x = cos(x);
double cos_y = cos(y);
// the behavior might depend on what's in here
if (cos_x != cos_y) {
std::cout << "Huh?!?\n"; // You might end up here when x == y!!
}
}
一些编译器选项?环形?任何想法?