diff --git a/inc/format.h b/inc/format.h index e3c3403..b967a4f 100644 --- a/inc/format.h +++ b/inc/format.h @@ -33,11 +33,11 @@ constexpr int get_output_len() { } -template -constexpr std::array get_init_array() { - std::array result; +template +constexpr std::array get_init_array() { + std::array result; - if constexpr (zeroed) { + if constexpr (fmt_node.has_zero_padding) { for (auto& c : result) c = '0'; } else { @@ -54,8 +54,7 @@ template constexpr std::array format_arg(arg_t arg) { check_fmt_params(); - std::array result = - get_init_array(); + auto result = get_init_array(); for (unsigned i = 1; (i <= result.size()) && arg > 0; ++i) { result[result.size() - i] = arg % 10 + 48; @@ -73,19 +72,20 @@ constexpr std::array format_arg(arg_t arg) { constexpr unsigned point_index = fmt_node.length - fmt_node.precision - 1; constexpr unsigned multiplier = const_pow(10, fmt_node.precision); - std::array result = - get_init_array(); + auto result = get_init_array(); result[point_index] = '.'; + arg = arg * multiplier; + for (int i = result.size() - 1; + (i > static_cast(point_index)) && (arg >= 1); --i) { - for (unsigned i = result.size() - 1; (i > point_index) && (arg >= 1); --i) { result[i] = static_cast(arg) % 10 + 48; arg = arg / 10; } - for (unsigned i = point_index - 1; (i >= 0) && (arg >= 1); --i) { + for (int i = point_index - 1; (i >= 0) && (arg >= 1); --i) { result[i] = static_cast(arg) % 10 + 48; arg = arg / 10; }