From 042b51287743615df77766a47e0df33e6a3e70ca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Sep 2021 16:59:53 +1000 Subject: [PATCH] AP_Declination: fixed rounding in mag field thanks to Angela for noticing this --- libraries/AP_Declination/AP_Declination.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Declination/AP_Declination.cpp b/libraries/AP_Declination/AP_Declination.cpp index 37dd1ed51c..bd50eaf0fa 100644 --- a/libraries/AP_Declination/AP_Declination.cpp +++ b/libraries/AP_Declination/AP_Declination.cpp @@ -37,8 +37,8 @@ bool AP_Declination::get_mag_field_ef(float latitude_deg, float longitude_deg, f bool valid_input_data = true; /* round down to nearest sampling resolution */ - int32_t min_lat = static_cast(static_cast(latitude_deg / SAMPLING_RES) * SAMPLING_RES); - int32_t min_lon = static_cast(static_cast(longitude_deg / SAMPLING_RES) * SAMPLING_RES); + int32_t min_lat = static_cast(static_cast(floorf(latitude_deg / SAMPLING_RES)) * SAMPLING_RES); + int32_t min_lon = static_cast(static_cast(floorf(longitude_deg / SAMPLING_RES)) * SAMPLING_RES); /* for the rare case of hitting the bounds exactly * the rounding logic wouldn't fit, so enforce it.