Replace best_diff when a better diff comes along

This commit is contained in:
shabbyrobe 2019-10-15 01:00:28 +11:00 committed by Stefan Haustein
parent 0721c1f9fd
commit 97ac9f02f9

View file

@ -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;