考虑以下代码:
#include <iostream>
using namespace std;
int main() {
double x = 1.77;
double y = 1.76;
double diff = x-y;
cout << "x-y = " << diff << endl;
if (diff <= 0.01)
{
cout << "x and y differ by less than 1.0/100 ..." << endl;
}
return 0;
}
以下是我得到的输出:
x-y = 0.01
但是我在这里看不到打印的x and y differ by less than 1.0/100...
,预期,因为x
和y
之间的差是0.01
。>