mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
feat: added support for printing powers of magnitude constants
This commit is contained in:
@ -146,6 +146,8 @@ constexpr Out copy_symbol_exponent(text_encoding encoding, bool negative_power,
|
||||
}
|
||||
constexpr auto txt = superscript<r.num>();
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
} else {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,9 +353,12 @@ template<typename CharT, std::output_iterator<CharT> Out, auto M, auto... Rest>
|
||||
[[nodiscard]] consteval auto mag_constants_text(Out out, magnitude<M, Rest...>, const unit_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
return ((out = copy_symbol<CharT>(get_base(M).symbol, fmt.encoding, negative_power, out)), ...,
|
||||
(print_separator<CharT>(out, fmt),
|
||||
out = copy_symbol<CharT>(get_base(Rest).symbol, fmt.encoding, negative_power, out)));
|
||||
auto to_symbol = [&]<typename T>(T v) {
|
||||
out = copy_symbol<CharT>(get_base(v).symbol, fmt.encoding, negative_power, out);
|
||||
constexpr ratio r = get_exponent(T{});
|
||||
return copy_symbol_exponent<CharT, abs(r.num), r.den>(fmt.encoding, negative_power, out);
|
||||
};
|
||||
return (to_symbol(M), ..., (print_separator<CharT>(out, fmt), to_symbol(Rest)));
|
||||
}
|
||||
|
||||
template<typename CharT, Magnitude auto Num, Magnitude auto Den, Magnitude auto NumConstants,
|
||||
@ -501,7 +504,6 @@ private:
|
||||
|
||||
[[nodiscard]] friend consteval auto _denominator(magnitude) { return _numerator(pow<-1>(magnitude{})); }
|
||||
|
||||
|
||||
[[nodiscard]] friend consteval auto _remove_positive_powers(magnitude)
|
||||
{
|
||||
return (magnitude<>{} * ... * detail::remove_positive_power(magnitude<Ms>{}));
|
||||
@ -717,8 +719,8 @@ constexpr Magnitude auto mag_ratio = detail::prime_factorization_v<N> / detail::
|
||||
/**
|
||||
* @brief Create a Magnitude which is some rational number raised to a rational power.
|
||||
*/
|
||||
template<std::intmax_t Base, int Num, int Den = 1>
|
||||
requires detail::gt_zero<Base>
|
||||
template<MagArg auto Base, int Num, int Den = 1>
|
||||
requires detail::gt_zero<detail::get_base_value(Base)>
|
||||
constexpr Magnitude auto mag_power = pow<Num, Den>(mag<Base>);
|
||||
|
||||
/**
|
||||
|
@ -168,6 +168,10 @@ static_assert(unit_symbol<usf{.encoding = ascii, .solidus = always}>(mag_ratio<1
|
||||
"[1/(2 pi) m]");
|
||||
static_assert(unit_symbol(mag_ratio<1, 2> * mag<pi> * metre) == "[𝜋/2 m]");
|
||||
|
||||
static_assert(unit_symbol(mag_power<pi, 2> * one) == "[𝜋²]");
|
||||
static_assert(unit_symbol<usf{.encoding = ascii}>(mag_power<pi, 2> * one) == "[pi^2]");
|
||||
static_assert(unit_symbol(mag_power<pi, 1, 2> * metre) == "[𝜋^(1/2) m]");
|
||||
static_assert(unit_symbol<usf{.encoding = ascii}>(mag_power<pi, 1, 2> * metre) == "[pi^(1/2) m]");
|
||||
|
||||
static_assert(unit_symbol(mag<pi> * mag<e> * one) == "[e 𝜋]");
|
||||
static_assert(unit_symbol(mag<e> * mag<pi> * one) == "[e 𝜋]");
|
||||
|
Reference in New Issue
Block a user