理解 float 和 double類型的變量的精度與存儲方式,先參考下面文章
http://blog.csdn.net/xiongchuquan/article/details/37767569
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const double c1 = 1e-6; //若2個變量是float類型,則一般參考比較變量爲c1 少數部分float類型的小數精度能達到1e-7
const double c2 = 1e-15; //若2個變量爲double類型 則一般參考比較變量爲c2 少數部分double類型的小數精度能達到1e-16
double a1 = 3.123456789012345;
double a2 = 3.123456789012346;
if ( fabs(a1 - a2) < c2)
cout << "a = b is true." <<endl;
else
cout << "a = b is false." <<endl;
return 0;
}