feat: common_unit selection algorithm improved to make rev + rad return rad
This commit is contained in:
1 parent
21d07a4cf4
commit
cff9e25d3e
4 files changed
+14
-7
No files matched your search
@@ -190,6 +190,12 @@ template<typename T>
|
||||
return is_rational(element) && get_exponent(element).num > 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval bool is_positive_integral_power(MagnitudeSpecExpr auto element)
|
||||
{
|
||||
auto exp = get_exponent(element);
|
||||
return exp.den == 1 && exp.num > 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Magnitude product implementation.
|
||||
[[nodiscard]] consteval bool less(MagnitudeSpecExpr auto lhs, MagnitudeSpecExpr auto rhs)
|
||||
@@ -431,6 +437,10 @@ private:
|
||||
// all below functions should in fact be in a `detail` namespace but are placed here to benefit from the ADL
|
||||
[[nodiscard]] friend consteval bool _is_integral(const magnitude&) { return (detail::is_integral(Ms) && ...); }
|
||||
[[nodiscard]] friend consteval bool _is_rational(const magnitude&) { return (detail::is_rational(Ms) && ...); }
|
||||
[[nodiscard]] friend consteval bool _is_positive_integral_power(const magnitude&)
|
||||
{
|
||||
return (detail::is_positive_integral_power(Ms) && ...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The value of a Magnitude in a desired type T.
|
||||
|
||||
@@ -674,9 +674,9 @@ template<Unit U1, Unit U2>
|
||||
constexpr auto canonical_lhs = get_canonical_unit(U1{});
|
||||
constexpr auto canonical_rhs = get_canonical_unit(U2{});
|
||||
|
||||
if constexpr (_is_integral(canonical_lhs.mag / canonical_rhs.mag))
|
||||
if constexpr (_is_positive_integral_power(canonical_lhs.mag / canonical_rhs.mag))
|
||||
return u2;
|
||||
else if constexpr (_is_integral(canonical_rhs.mag / canonical_lhs.mag))
|
||||
else if constexpr (_is_positive_integral_power(canonical_rhs.mag / canonical_lhs.mag))
|
||||
return u1;
|
||||
else {
|
||||
if constexpr (detail::unit_less<U1, U2>::value)
|
||||
|
||||
Reference in new issue
Block a user