diff --git a/lib/turbomath/turbomath.cpp b/lib/turbomath/turbomath.cpp index e74f5b2c..80837695 100644 --- a/lib/turbomath/turbomath.cpp +++ b/lib/turbomath/turbomath.cpp @@ -255,9 +255,7 @@ float fsign(float y) { return (0.0f < y) - (y < 0.0f); } // ISA standard atmosphere up to 11kft: float alt(float press) { -#define ISA_PRESSURE (101325.0) // Pa -#define ISA_EXPONENT (0.190326730028458) -#define ISA_SCALE_FACTOR (44318.1386038261) //m + return (1.0-pow(press/ISA_PRESSURE,ISA_EXPONENT))*ISA_SCALE_FACTOR; } diff --git a/lib/turbomath/turbomath.h b/lib/turbomath/turbomath.h index d814235f..67bc5ed7 100644 --- a/lib/turbomath/turbomath.h +++ b/lib/turbomath/turbomath.h @@ -39,6 +39,9 @@ namespace turbomath { +#define ISA_PRESSURE (101325.0) // Pa +#define ISA_EXPONENT (0.190326730028458) +#define ISA_SCALE_FACTOR (44318.1386038261) //m float fsign(float y); diff --git a/test/turbotrig_test.cpp b/test/turbotrig_test.cpp index 3e0f2622..b2ac54f2 100644 --- a/test/turbotrig_test.cpp +++ b/test/turbotrig_test.cpp @@ -90,41 +90,6 @@ turbomath::Quaternion random_quaternions[25] = { turbomath::Quaternion(-0.177027678376, 0.214558558928, -0.992910369554, 0.592964390132), turbomath::Quaternion(0.0979109306209, 0.121890109199, 0.126418158551, 0.242200145606)}; -TEST(TurboMath, atan) -{ - for (float i = -200.0; i <= 200.0; i += 0.001) { - EXPECT_NEAR(turbomath::atan(i), atan(i), 0.0001); - } -} - -TEST(TurboMath, sin_cos) -{ - for (float i = -200.0; i <= 200.0; i += 0.001) { - EXPECT_NEAR(turbomath::sin(i), sin(i), 0.0002); - EXPECT_NEAR(turbomath::cos(i), cos(i), 0.0002); - } -} - -TEST(TurboMath, atan2) -{ - for (float i = -100.0; i <= 100.0; i += 0.1) { - for (float j = -1.0; j <= 1.0; j += 0.001) { - if (fabs(j) > 0.0001) { EXPECT_NEAR(turbomath::atan2(i, j), atan2(i, j), 0.001); } - } - } -} - -TEST(TurboMath, asin) -{ - for (float i = -1.0; i <= 1.0; i += 0.001) { - if (fabs(i) < 0.95) { - EXPECT_NEAR(turbomath::asin(i), asin(i), 0.0001); - } else { - EXPECT_NEAR(turbomath::asin(i), asin(i), 0.2); - } - } -} - TEST(TurboMath, fastAlt) { // out of bounds @@ -135,8 +100,7 @@ TEST(TurboMath, fastAlt) float trueResult = 0.0; for (int i = 69682; i < 106597; i++) { trueResult = - static_cast((1.0 - pow(static_cast(i) / 101325, 0.190284)) * 145366.45) - * static_cast(0.3048); + static_cast((1.0 - pow(static_cast(i) /ISA_PRESSURE, ISA_EXPONENT)) * ISA_SCALE_FACTOR); EXPECT_NEAR(turbomath::alt(i), trueResult, .15); // arbitrarily chose <= .15m since fast_alt isn't accurate enough for EXPECT_CLOSE, // but being within .15 meters of the correct result seems pretty good to me