From 6649b8e0ca57d65b193b932384c685d70c078b1c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 7 Sep 2019 14:23:19 -0700 Subject: [PATCH] value -> bigit --- include/fmt/format-inl.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index b8c6d3ac..4027b7a5 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -468,16 +468,23 @@ FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) { class bigint { private: - basic_memory_buffer value_; - static FMT_CONSTEXPR_DECL const int radix = 32; + // A bigint is stored as an array of bigits (big digits), with bigit at index + // 0 being the least significant one. + using bigit = uint32_t; + basic_memory_buffer bigits_; + + static FMT_CONSTEXPR_DECL const int bigit_bits = bits::value; friend struct formatter; public: explicit bigint(uint64_t n) { - value_.resize(2); - value_[0] = n & ~uint32_t(0); - value_[1] = static_cast(n >> 32); + int num_bigits = bits::value / bigit_bits; + bigits_.resize(num_bigits); + for (int i = 0; i < num_bigits; ++i) { + bigits_[i] = n & ~bigit(0); + n >>= bigit_bits; + } } bigint(const bigint&) = delete; @@ -862,8 +869,8 @@ template <> struct formatter { format_context& ctx) { auto out = ctx.out(); bool first = true; - for (auto i = n.value_.size(); i > 0; --i) { - auto value = n.value_[i - 1]; + for (auto i = n.bigits_.size(); i > 0; --i) { + auto value = n.bigits_[i - 1]; if (first) { if (value == 0 && i > 1) continue; out = format_to(out, "{:x}", value);