2022-04-14 12:20:41 +00:00
|
|
|
#include "value_index.h"
|
2024-01-19 20:20:37 +00:00
|
|
|
#include <math.h>
|
2022-04-14 12:20:41 +00:00
|
|
|
|
2024-01-19 20:20:37 +00:00
|
|
|
size_t value_index_int32(const int32_t value, const int32_t values[], size_t values_count) {
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < values_count; i++) {
|
|
|
|
if(value == values[i]) {
|
2023-06-06 17:46:01 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 20:20:37 +00:00
|
|
|
|
2023-06-06 17:46:01 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2024-01-19 20:20:37 +00:00
|
|
|
size_t value_index_uint32(const uint32_t value, const uint32_t values[], size_t values_count) {
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < values_count; i++) {
|
|
|
|
if(value == values[i]) {
|
2022-04-14 12:20:41 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 20:20:37 +00:00
|
|
|
|
2022-04-14 12:20:41 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2024-01-19 20:20:37 +00:00
|
|
|
size_t value_index_float(const float value, const float values[], size_t values_count) {
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < values_count; i++) {
|
|
|
|
const float epsilon = fabsf(values[i] * 0.01f);
|
|
|
|
if(fabsf(values[i] - value) <= epsilon) {
|
2022-04-14 12:20:41 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 20:20:37 +00:00
|
|
|
|
2022-04-14 12:20:41 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2024-01-19 20:20:37 +00:00
|
|
|
size_t value_index_bool(const bool value, const bool values[], size_t values_count) {
|
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < values_count; i++) {
|
2022-04-14 12:20:41 +00:00
|
|
|
if(value == values[i]) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-01-19 20:20:37 +00:00
|
|
|
|
2022-04-14 12:20:41 +00:00
|
|
|
return index;
|
|
|
|
}
|