Skip to content

Commit

Permalink
[wpimath] Make units math functions constexpr (wpilibsuite#6345)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Feb 6, 2024
1 parent 3b2a238 commit 4f9d737
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 69 deletions.
6 changes: 4 additions & 2 deletions wpimath/src/main/native/include/units/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
#include <fmt/format.h>
#endif

#include <gcem.hpp>

//------------------------------
// STRING FORMATTER
//------------------------------
Expand Down Expand Up @@ -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));
}

/**
Expand Down
Loading

0 comments on commit 4f9d737

Please sign in to comment.