From e1a17ab1f0bf25968fa8c421dc1d9e737a5fc018 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Thu, 7 Jul 2022 16:33:51 +0000 Subject: [PATCH] Use variables instead of ratio members This prepares us for a time when we won't _have_ the `ratio` members (because we'll be using `Magnitude`). --- src/core/include/units/bits/unit_text.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/include/units/bits/unit_text.h b/src/core/include/units/bits/unit_text.h index 45345468..49c1c3e1 100644 --- a/src/core/include/units/bits/unit_text.h +++ b/src/core/include/units/bits/unit_text.h @@ -35,21 +35,25 @@ inline constexpr basic_symbol_text base_multiplier("\u00D7 10", "x 10"); template constexpr auto ratio_text() { - if constexpr (R.num == 1 && R.den == 1 && R.exp != 0) { - return base_multiplier + superscript(); - } else if constexpr (R.num != 1 || R.den != 1 || R.exp != 0) { - auto txt = basic_fixed_string("[") + regular(); - if constexpr (R.den == 1) { - if constexpr (R.exp == 0) { + constexpr auto num_value = R.num; + constexpr auto den_value = R.den; + constexpr auto exp10 = R.exp; + + if constexpr (num_value == 1 && den_value == 1 && exp10 != 0) { + return base_multiplier + superscript(); + } else if constexpr (num_value != 1 || den_value != 1 || exp10 != 0) { + auto txt = basic_fixed_string("[") + regular(); + if constexpr (den_value == 1) { + if constexpr (exp10 == 0) { return txt + basic_fixed_string("]"); } else { - return txt + " " + base_multiplier + superscript() + basic_fixed_string("]"); + return txt + " " + base_multiplier + superscript() + basic_fixed_string("]"); } } else { - if constexpr (R.exp == 0) { - return txt + basic_fixed_string("/") + regular() + basic_fixed_string("]"); + if constexpr (exp10 == 0) { + return txt + basic_fixed_string("/") + regular() + basic_fixed_string("]"); } else { - return txt + basic_fixed_string("/") + regular() + " " + base_multiplier + superscript() + + return txt + basic_fixed_string("/") + regular() + " " + base_multiplier + superscript() + basic_fixed_string("]"); } }