forked from mpusz/mp-units
fix: printing of symbols with fractional powers fixed
This commit is contained in:
@@ -642,8 +642,8 @@ constexpr auto unit_symbol_impl(Out out, const power<F, Num, Den...>&, unit_symb
|
|||||||
constexpr ratio r = power<F, Num, Den...>::exponent;
|
constexpr ratio r = power<F, Num, Den...>::exponent;
|
||||||
if constexpr (r.den != 1) {
|
if constexpr (r.den != 1) {
|
||||||
// add root part
|
// add root part
|
||||||
constexpr auto txt = txt + basic_fixed_string("^(") + regular<r.num>() + basic_fixed_string("/") +
|
constexpr auto txt = basic_fixed_string("^(") + regular<r.num>() + basic_fixed_string("/") + regular<r.den>() +
|
||||||
regular<r.den>() + basic_fixed_string(")");
|
basic_fixed_string(")");
|
||||||
return copy<CharT>(txt, fmt.encoding, out);
|
return copy<CharT>(txt, fmt.encoding, out);
|
||||||
} else if constexpr (r.num != 1) {
|
} else if constexpr (r.num != 1) {
|
||||||
// add exponent part
|
// add exponent part
|
||||||
|
@@ -478,6 +478,10 @@ static_assert(unit_symbol(kilogram / metre / square<second>, {.encoding = ascii,
|
|||||||
"kg m^-1 s^-2");
|
"kg m^-1 s^-2");
|
||||||
static_assert(unit_symbol(kilogram / metre / square<second>, {.denominator = always_negative, .separator = dot}) ==
|
static_assert(unit_symbol(kilogram / metre / square<second>, {.denominator = always_negative, .separator = dot}) ==
|
||||||
"kg⋅m⁻¹⋅s⁻²");
|
"kg⋅m⁻¹⋅s⁻²");
|
||||||
|
static_assert(unit_symbol(pow<123>(metre)) == "m¹²³");
|
||||||
|
static_assert(unit_symbol(pow<1, 2>(metre)) == "m^(1/2)");
|
||||||
|
static_assert(unit_symbol(pow<3, 5>(metre)) == "m^(3/5)");
|
||||||
|
static_assert(unit_symbol(pow<1, 2>(metre / second)) == "m^(1/2)/s^(1/2)");
|
||||||
|
|
||||||
#endif // __cpp_lib_constexpr_string
|
#endif // __cpp_lib_constexpr_string
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user