[wpimath] Make units math functions constexpr (#6345)

This commit is contained in:
Tyler Veness
2024-02-05 22:43:12 -08:00
committed by GitHub
parent 3b2a2381b6
commit 4f9d73783b
2 changed files with 75 additions and 69 deletions

View File

@@ -81,6 +81,8 @@
#include <fmt/format.h>
#endif
#include <gcem.hpp>
//------------------------------
// STRING FORMATTER
//------------------------------
@@ -2803,10 +2805,10 @@ namespace units
* @returns new unit_t, raised to the given exponent
*/
template<int power, class UnitType, class = typename std::enable_if<traits::has_linear_scale<UnitType>::value, int>>
inline auto pow(const UnitType& value) noexcept -> unit_t<typename units::detail::power_of_unit<power, typename units::traits::unit_t_traits<UnitType>::unit_type>::type, typename units::traits::unit_t_traits<UnitType>::underlying_type, linear_scale>
inline constexpr auto pow(const UnitType& value) noexcept -> unit_t<typename units::detail::power_of_unit<power, typename units::traits::unit_t_traits<UnitType>::unit_type>::type, typename units::traits::unit_t_traits<UnitType>::underlying_type, linear_scale>
{
return unit_t<typename units::detail::power_of_unit<power, typename units::traits::unit_t_traits<UnitType>::unit_type>::type, typename units::traits::unit_t_traits<UnitType>::underlying_type, linear_scale>
(std::pow(value(), power));
(gcem::pow(value(), power));
}
/**