diff --git a/libraries/AP_Math/matrix_alg.cpp b/libraries/AP_Math/matrix_alg.cpp index 881f6378ea..c172db7271 100644 --- a/libraries/AP_Math/matrix_alg.cpp +++ b/libraries/AP_Math/matrix_alg.cpp @@ -18,9 +18,15 @@ */ #pragma GCC optimize("O3") -#include #include + #include +#if CONFIG_HAL_BOARD == HAL_BOARD_SITL +#include +#endif + +#include + extern const AP_HAL::HAL& hal; //TODO: use higher precision datatypes to achieve more accuracy for matrix algebra operations @@ -279,6 +285,13 @@ bool inverse4x4(float m[],float invOut[]) float inv[16], det; uint8_t i; +#if CONFIG_HAL_BOARD == HAL_BOARD_SITL + int old = fedisableexcept(FE_OVERFLOW); + if (old < 0) { + hal.console->printf("inverse4x4(): warning: error on disabling FE_OVERFLOW floating point exception\n"); + } +#endif + inv[0] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] + @@ -393,6 +406,12 @@ bool inverse4x4(float m[],float invOut[]) det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; +#if CONFIG_HAL_BOARD == HAL_BOARD_SITL + if (old >= 0 && feenableexcept(old) < 0) { + hal.console->printf("inverse4x4(): warning: error on restoring floating exception mask\n"); + } +#endif + if (is_zero(det) || isinf(det)){ return false; }