fixed calculation of magentic table values by using floor instead of int casting

This commit is contained in:
Sebastian Verling
2019-05-24 09:09:26 +02:00
committed by Lorenz Meier
parent 54ac147ae8
commit 710c52980e
3 changed files with 14 additions and 2 deletions
+3 -2
View File
@@ -49,6 +49,7 @@
#include <stdint.h>
using math::constrain;
using math::floorf;
/** set this always to the sampling in degrees for the table below */
static constexpr float SAMPLING_RES = 10.0f;
@@ -139,8 +140,8 @@ get_table_data(float lat, float lon, const int8_t table[13][37])
}
/* round down to nearest sampling resolution */
float min_lat = int(lat / SAMPLING_RES) * SAMPLING_RES;
float min_lon = int(lon / SAMPLING_RES) * SAMPLING_RES;
float min_lat = floorf(lat / SAMPLING_RES) * SAMPLING_RES;
float min_lon = floorf(lon / SAMPLING_RES) * SAMPLING_RES;
/* find index of nearest low sampling point */
unsigned min_lat_index = get_lookup_table_index(&min_lat, SAMPLING_MIN_LAT, SAMPLING_MAX_LAT);