forked from mpusz/mp-units
Printing of uknown non-coherent units fixed
This commit is contained in:
@@ -145,12 +145,14 @@ constexpr auto unit_text()
|
|||||||
return U::symbol;
|
return U::symbol;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// print as a prefix or ratio of a reference unit
|
// print as a prefix or ratio of a coherent unit
|
||||||
auto prefix_txt = prefix_or_ratio_text<typename U::ratio, typename U::reference::prefix_type>();
|
using coherent_unit = dimension_unit<Dim>;
|
||||||
|
using ratio = ratio_divide<typename U::ratio, typename coherent_unit::ratio>;
|
||||||
|
auto prefix_txt = prefix_or_ratio_text<ratio, typename U::reference::prefix_type>();
|
||||||
|
|
||||||
if constexpr(has_symbol<typename U::reference>) {
|
if constexpr(has_symbol<coherent_unit>) {
|
||||||
// use predefined reference unit symbol
|
// use predefined coherent unit symbol
|
||||||
return prefix_txt + U::reference::symbol;
|
return prefix_txt + coherent_unit::symbol;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// use derived dimension ingredients to create a unit symbol
|
// use derived dimension ingredients to create a unit symbol
|
||||||
|
@@ -188,4 +188,9 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
|||||||
CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");
|
CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");
|
||||||
CHECK(fmt::format("{}", 1q_au * 1q_au) == "1 [2237952291797391849 × 10⁴] m²");
|
CHECK(fmt::format("{}", 1q_au * 1q_au) == "1 [2237952291797391849 × 10⁴] m²");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("unknown scaled unit with reference different than the dimension's coherent unit")
|
||||||
|
{
|
||||||
|
CHECK(fmt::format("{}", mass<units::scaled_unit<units::ratio<2, 3>, gram>>(1)) == "1 [2/3 × 10⁻³] kg");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user