diff --git a/src/include/units/bits/deduced_symbol_text.h b/src/include/units/bits/deduced_symbol_text.h index 05015919..bf35c126 100644 --- a/src/include/units/bits/deduced_symbol_text.h +++ b/src/include/units/bits/deduced_symbol_text.h @@ -28,11 +28,11 @@ namespace units::detail { -template +template constexpr auto operator_text() { if constexpr(Idx == 0) { - if constexpr(Divide) { + if constexpr(Divide && NegativeExpCount == 1) { return basic_fixed_string("1/"); } else { @@ -40,7 +40,7 @@ constexpr auto operator_text() } } else { - if constexpr(Divide) { + if constexpr(Divide && NegativeExpCount == 1) { return basic_fixed_string("/"); } else { @@ -49,28 +49,40 @@ constexpr auto operator_text() } } -template +template constexpr auto exp_text() { // get calculation operator + symbol - const auto txt = operator_text() + Symbol; + const auto txt = operator_text() + Symbol; if constexpr(E::den != 1) { // add root part return txt + basic_fixed_string("^(") + regular() + basic_fixed_string("/") + regular() + basic_fixed_string(")"); } - else if constexpr(abs(E::num) != 1) { + else if constexpr(E::num != 1) { // add exponent part - return txt + superscript(); + if constexpr(NegativeExpCount > 1) { // no '/' sign here (only negative exponents) + return txt + superscript(); + } + else if constexpr(E::num != -1) { // -1 is replaced with '/' sign here + return txt + superscript(); + } + else { + return txt; + } } else { return txt; } } +template +inline constexpr int negative_exp_count = ((Es::num < 0 ? 1 : 0) + ...); + template constexpr auto deduced_symbol_text(exp_list, std::index_sequence) { - return (exp_text() + ...); + constexpr auto neg_exp = negative_exp_count; + return (exp_text() + ...); } template diff --git a/src/include/units/bits/external/text_tools.h b/src/include/units/bits/external/text_tools.h index 7e102fe7..aa6f9a03 100644 --- a/src/include/units/bits/external/text_tools.h +++ b/src/include/units/bits/external/text_tools.h @@ -41,21 +41,25 @@ template<> inline constexpr basic_fixed_string superscript_number<7> = "\u2077"; template<> inline constexpr basic_fixed_string superscript_number<8> = "\u2078"; template<> inline constexpr basic_fixed_string superscript_number<9> = "\u2079"; +inline constexpr basic_fixed_string superscript_minus = "\u207b"; + template - requires (Value >= 0) constexpr auto superscript() { - if constexpr(Value < 10) + if constexpr(Value < 0) + return superscript_minus + superscript<-Value>(); + else if constexpr(Value < 10) return superscript_number; else return superscript() + superscript(); } template - requires (Value >= 0) constexpr auto regular() { - if constexpr(Value < 10) + if constexpr(Value < 0) + return basic_fixed_string("-") + superscript<-Value>(); + else if constexpr(Value < 10) return basic_fixed_string(static_cast('0' + Value)); else return regular() + regular(); diff --git a/src/include/units/bits/unit_text.h b/src/include/units/bits/unit_text.h index f1fc8152..bed0f58d 100644 --- a/src/include/units/bits/unit_text.h +++ b/src/include/units/bits/unit_text.h @@ -74,7 +74,8 @@ constexpr auto prefix_or_ratio_text() template constexpr auto derived_dimension_unit_text(exp_list, std::index_sequence) { - return (exp_text::symbol, Idxs>() + ...); + constexpr auto neg_exp = negative_exp_count; + return (exp_text::symbol, neg_exp, Idxs>() + ...); } template