Replace best_diff when a better diff comes along
This commit is contained in:
parent
0721c1f9fd
commit
97ac9f02f9
1 changed files with 3 additions and 1 deletions
|
@ -301,8 +301,10 @@ int best_index(int value, const int data[], int count) {
|
||||||
int best_diff = std::abs(data[0] - value);
|
int best_diff = std::abs(data[0] - value);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = 1; i < count; i++) {
|
for (int i = 1; i < count; i++) {
|
||||||
if (std::abs(data[i] - value) < best_diff) {
|
int diff = std::abs(data[i] - value);
|
||||||
|
if (diff < best_diff) {
|
||||||
result = i;
|
result = i;
|
||||||
|
best_diff = diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue