diff --git a/src/shared/units/Acceleration.h b/src/shared/units/Acceleration.h index aa61a369fa77e4035e975f48584cd4f9dca0c4bd..40a607fcb0eb38e31e2c4e2a5527104f1a5c272c 100644 --- a/src/shared/units/Acceleration.h +++ b/src/shared/units/Acceleration.h @@ -22,6 +22,8 @@ #pragma once +#include <utils/Constants.h> + #include <ratio> #include "Units.h" @@ -43,7 +45,16 @@ ToAcceleration acceleration_cast(FromAcceleration const& from) } using MeterPerSecondSquared = Acceleration<>; // Acceleration in m/s^2 -using G = Acceleration<std::ratio<981, 100>>; // Acceleration in Gs +using G = + Acceleration<std::ratio<static_cast<std::intmax_t>(Constants::g * 1e10), + static_cast<std::intmax_t>(1e10)>>; // Acceleration + // in Gs + +/** + * Assert that we have enough precision to represent the constant value. + */ +static_assert(MeterPerSecondSquared{G{1}}.value() == Constants::g, + "Not enough precision to represent g in m/s^2"); // Floats constexpr auto operator""_mps2(long double n) diff --git a/src/tests/catch/test-units.cpp b/src/tests/catch/test-units.cpp index 456aacb4ab877706607fda6eed853c3829d2f5b5..1e872eb957c28d0056f2723a0c1bb0c6576146ab 100644 --- a/src/tests/catch/test-units.cpp +++ b/src/tests/catch/test-units.cpp @@ -73,7 +73,7 @@ TEST_CASE("Units Test") REQUIRE(MeterPerSecond(1) == speed_cast<MeterPerSecond>(KilometerPerHour(3.6))); - REQUIRE(MeterPerSecondSquared(9.81) == + REQUIRE(MeterPerSecondSquared(Constants::g) == acceleration_cast<MeterPerSecondSquared>(G(1))); // Test operators