mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 13:44:27 +02:00
fix: magnitude get_value
fixed for clang-17
This commit is contained in:
@@ -515,11 +515,11 @@ MP_UNITS_EXPORT_BEGIN
|
|||||||
*/
|
*/
|
||||||
template<typename T, auto... Ms>
|
template<typename T, auto... Ms>
|
||||||
requires(decltype(is_integral(magnitude<Ms...>{}))::value) || treat_as_floating_point<T>
|
requires(decltype(is_integral(magnitude<Ms...>{}))::value) || treat_as_floating_point<T>
|
||||||
constexpr auto get_value(const magnitude<Ms...>&)
|
constexpr T get_value(const magnitude<Ms...>&)
|
||||||
{
|
{
|
||||||
// Force the expression to be evaluated in a constexpr context, to catch, e.g., overflow.
|
// Force the expression to be evaluated in a constexpr context, to catch, e.g., overflow.
|
||||||
constexpr auto result = detail::checked_static_cast<T>((detail::compute_base_power<T>(Ms) * ... * T{1}));
|
constexpr T result = detail::checked_static_cast<T>((detail::compute_base_power<T>(Ms) * ... * T{1}));
|
||||||
return std::integral_constant<T, result>{};
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -859,14 +859,14 @@ template<Magnitude auto M>
|
|||||||
// TODO address the below
|
// TODO address the below
|
||||||
static_assert(base{} == num{} / den{}, "Printing rational powers, or irrational bases, not yet supported");
|
static_assert(base{} == num{} / den{}, "Printing rational powers, or irrational bases, not yet supported");
|
||||||
|
|
||||||
using num_value = decltype(get_value<std::intmax_t>(num{}));
|
constexpr auto num_value = get_value<std::intmax_t>(num{});
|
||||||
using den_value = decltype(get_value<std::intmax_t>(den{}));
|
constexpr auto den_value = get_value<std::intmax_t>(den{});
|
||||||
|
|
||||||
if constexpr (num_value{} == 1 && den_value{} == 1 && exp10 != 0) {
|
if constexpr (num_value == 1 && den_value == 1 && exp10 != 0) {
|
||||||
return base_multiplier + superscript<exp10>();
|
return base_multiplier + superscript<exp10>();
|
||||||
} else if constexpr (num_value{} != 1 || den_value{} != 1 || exp10 != 0) {
|
} else if constexpr (num_value != 1 || den_value != 1 || exp10 != 0) {
|
||||||
auto txt = symbol_text("[") + regular<num_value{}>();
|
auto txt = symbol_text("[") + regular<num_value>();
|
||||||
if constexpr (den_value{} == 1) {
|
if constexpr (den_value == 1) {
|
||||||
if constexpr (exp10 == 0) {
|
if constexpr (exp10 == 0) {
|
||||||
return txt + symbol_text("]");
|
return txt + symbol_text("]");
|
||||||
} else {
|
} else {
|
||||||
@@ -874,9 +874,9 @@ template<Magnitude auto M>
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if constexpr (exp10 == 0) {
|
if constexpr (exp10 == 0) {
|
||||||
return txt + symbol_text("/") + regular<den_value{}>() + symbol_text("]");
|
return txt + symbol_text("/") + regular<den_value>() + symbol_text("]");
|
||||||
} else {
|
} else {
|
||||||
return txt + symbol_text("/") + regular<den_value{}>() + symbol_text(" ") + base_multiplier +
|
return txt + symbol_text("/") + regular<den_value>() + symbol_text(" ") + base_multiplier +
|
||||||
superscript<exp10>() + symbol_text("]");
|
superscript<exp10>() + symbol_text("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -118,8 +118,7 @@ namespace detail {
|
|||||||
constexpr auto as_ratio(Magnitude auto m)
|
constexpr auto as_ratio(Magnitude auto m)
|
||||||
requires(decltype(is_rational(decltype(m){}))::value)
|
requires(decltype(is_rational(decltype(m){}))::value)
|
||||||
{
|
{
|
||||||
return std::ratio<decltype(get_value<std::intmax_t>(numerator(m))){},
|
return std::ratio<get_value<std::intmax_t>(numerator(m)), get_value<std::intmax_t>(denominator(m))>{};
|
||||||
decltype(get_value<std::intmax_t>(denominator(m))){}>{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
Reference in New Issue
Block a user