forked from mpusz/mp-units
ratio_text
improved to omit den == 1
for exp != 0
This commit is contained in:
@@ -29,7 +29,10 @@ namespace units::detail {
|
|||||||
template<typename Ratio>
|
template<typename Ratio>
|
||||||
constexpr auto ratio_text()
|
constexpr auto ratio_text()
|
||||||
{
|
{
|
||||||
if constexpr(Ratio::num != 1 || Ratio::den != 1 || Ratio::exp != 0) {
|
if constexpr(Ratio::num == 1 && Ratio::den == 1 && Ratio::exp != 0) {
|
||||||
|
return basic_fixed_string("\u00D7 10") + superscript<Ratio::exp>() + basic_fixed_string(" ");
|
||||||
|
}
|
||||||
|
else if constexpr(Ratio::num != 1 || Ratio::den != 1 || Ratio::exp != 0) {
|
||||||
auto txt = basic_fixed_string("[") + regular<Ratio::num>();
|
auto txt = basic_fixed_string("[") + regular<Ratio::num>();
|
||||||
if constexpr(Ratio::den == 1) {
|
if constexpr(Ratio::den == 1) {
|
||||||
if constexpr(Ratio::exp == 0) {
|
if constexpr(Ratio::exp == 0) {
|
||||||
|
@@ -298,7 +298,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
|
|||||||
|
|
||||||
SECTION("iostream")
|
SECTION("iostream")
|
||||||
{
|
{
|
||||||
CHECK(stream.str() == "8 [1 × 10⁻²]m³");
|
CHECK(stream.str() == "8 × 10⁻² m³");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fmt with default format {} on a quantity")
|
SECTION("fmt with default format {} on a quantity")
|
||||||
@@ -430,7 +430,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
|
|||||||
|
|
||||||
SECTION("iostream")
|
SECTION("iostream")
|
||||||
{
|
{
|
||||||
CHECK(stream.str() == "8 [1 × 10³]m⋅s");
|
CHECK(stream.str() == "8 × 10³ m⋅s");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fmt with default format {} on a quantity")
|
SECTION("fmt with default format {} on a quantity")
|
||||||
@@ -493,7 +493,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
|
|||||||
|
|
||||||
SECTION("iostream")
|
SECTION("iostream")
|
||||||
{
|
{
|
||||||
CHECK(stream.str() == "8 [1 × 10⁵]cm⋅g⋅s");
|
CHECK(stream.str() == "8 × 10⁵ cm⋅g⋅s");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fmt with default format {} on a quantity")
|
SECTION("fmt with default format {} on a quantity")
|
||||||
@@ -934,10 +934,3 @@ TEST_CASE("quantity_cast", "[text][ostream]")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Giving a precision specification
|
|
||||||
// in the chrono-format-spec is valid only for std::chrono::duration types where the representation type Rep
|
|
||||||
// is a floating-point type. For all other Rep types, a format_error shall be thrown if the chrono-format-spec
|
|
||||||
// contains a precision specification.
|
|
||||||
|
|
||||||
// string s = format("{:=>8}", 42ms); // value of s is "====42ms"
|
|
||||||
|
Reference in New Issue
Block a user