1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

Fix use of floating point math functions

This commit is contained in:
Mathias Rasmussen 2021-12-03 03:58:19 +01:00
parent 4c034d67ee
commit 87c259a26e
9 changed files with 20 additions and 19 deletions

View file

@ -72,7 +72,7 @@ extern "C" {
#include "unittest_macros.h"
#include "gtest/gtest.h"
const float sqrt2over2 = sqrt(2) / 2.0f;
const float sqrt2over2 = sqrtf(2) / 2.0f;
TEST(FlightImuTest, TestCalculateRotationMatrix)
{

View file

@ -207,8 +207,8 @@ TEST(MathsUnittest, TestFastTrigonometrySinCos)
{
double sinError = 0;
for (float x = -10 * M_PI; x < 10 * M_PI; x += M_PI / 300) {
double approxResult = sin_approx(x);
double libmResult = sinf(x);
float approxResult = sin_approx(x);
double libmResult = sin(x);
sinError = MAX(sinError, fabs(approxResult - libmResult));
}
printf("sin_approx maximum absolute error = %e\n", sinError);
@ -216,8 +216,8 @@ TEST(MathsUnittest, TestFastTrigonometrySinCos)
double cosError = 0;
for (float x = -10 * M_PI; x < 10 * M_PI; x += M_PI / 300) {
double approxResult = cos_approx(x);
double libmResult = cosf(x);
float approxResult = cos_approx(x);
double libmResult = cos(x);
cosError = MAX(cosError, fabs(approxResult - libmResult));
}
printf("cos_approx maximum absolute error = %e\n", cosError);
@ -229,8 +229,8 @@ TEST(MathsUnittest, TestFastTrigonometryATan2)
double error = 0;
for (float x = -1.0f; x < 1.0f; x += 0.01) {
for (float y = -1.0f; x < 1.0f; x += 0.001) {
double approxResult = atan2_approx(y, x);
double libmResult = atan2f(y, x);
float approxResult = atan2_approx(y, x);
double libmResult = atan2(y, x);
error = MAX(error, fabs(approxResult - libmResult));
}
}
@ -242,7 +242,7 @@ TEST(MathsUnittest, TestFastTrigonometryACos)
{
double error = 0;
for (float x = -1.0f; x < 1.0f; x += 0.001) {
double approxResult = acos_approx(x);
float approxResult = acos_approx(x);
double libmResult = acos(x);
error = MAX(error, fabs(approxResult - libmResult));
}

View file

@ -224,7 +224,7 @@ void setStickPosition(int axis, float stickRatio) {
// All calculations will have 10% tolerance
float calculateTolerance(float input) {
return fabs(input * 0.1f);
return fabsf(input * 0.1f);
}
TEST(pidControllerTest, testInitialisation)