1
我正試圖在CppUnit中實現邊界測試。我想檢查限制值本身以及圍繞此限制的邊界。在C++中使用CppUnit進行邊界值分析
對於上邊界我想添加可能的最小墨跡。對於double
這個增量可以
numeric_limits<double>::epsilon()
訪問但是,如果我加入小量到我的極限,我得到不是非數字(NAN)的結果是:
#include <stdio.h>
#include <iostream>
#include <limits>
#include <math.h>
using namespace std;
const double WARNING_LIMIT = 8000.0;
int main(void) {
double warningLowerLimit = WARNING_LIMIT - numeric_limits<double>::epsilon();
if(warningLowerLimit < WARNING_LIMIT) {
cout << "lower" << endl;
}
else if (warningLowerLimit > WARNING_LIMIT) {
cout << "upper" << endl;
}
else if (fabs(warningLowerLimit) < 0.001) {
cout << "same" << endl;
}
else {
cout << "NaN" << endl; // <-- result
}
}
有人可以請給我解釋一下,爲什麼結果不會低於極限?
問候