arrays - C++ Checking if a double is within .1 of another double (+/-) -
i'm running bit of code need compare 2 2d arrays variance. i've tried using following line of code check , compare values, test fails every time = if(arr1[a][b] != arr2[a][b] || arr1[a][b] + .1 != arr2[a][b] || arr1[a][b] - .1 != arr2[a][b]) {
.
i know failing because of ||
statement, because 1 of requirements met. i've got find way determine if double stored in specific location in array matches other array in parallel location.
here's full code:
int numberoffailedcompares = 0; for(int = 0; < 20; a++) { int b = 0; while(b < 20) { if(arr1[a][b] != arr2[a][b] || arr1[a][b] + .1 != arr2[a][b] || arr1[a][b] - .1 != arr2[a][b]) { numberoffailedcompares++; cout << numberoffailedcompares << endl; } b++; } }
is there statement in c++ allow me check if value within +/- .1 threshold?
if(arrlocation1 (+/- .1) == arrlocation1) { ... }
"variance" means "within x", , not "equal plus x or minus x". instead of comparing equality, compare less/greater variance. so, example, test variance of +/- .1:
if (b >= a-.1 && b <= a+.1)
Comments
Post a Comment