From bed134a4aad3de93b2ba0e1a59a51b662243b7e8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 27 Feb 2020 15:29:46 -0800 Subject: [PATCH] Tentative fix for default template param in friend error --- include/fmt/format-inl.h | 41 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 55bf1c44..1ac206a8 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -336,6 +336,10 @@ class fp { private: using significand_type = uint64_t; + public: + significand_type f; + int e; + // All sizes are in bits. // Subtract 1 to account for an implicit most significant bit in the // normalized form. @@ -343,11 +347,6 @@ class fp { std::numeric_limits::digits - 1; static FMT_CONSTEXPR_DECL const uint64_t implicit_bit = 1ULL << double_significand_size; - - public: - significand_type f; - int e; - static FMT_CONSTEXPR_DECL const int significand_size = bits::value; @@ -358,22 +357,6 @@ class fp { // errors on platforms where double is not IEEE754. template explicit fp(Double d) { assign(d); } - // Normalizes the value converted from double and multiplied by (1 << SHIFT). - template friend fp normalize(fp value) { - // Handle subnormals. - const auto shifted_implicit_bit = fp::implicit_bit << SHIFT; - while ((value.f & shifted_implicit_bit) == 0) { - value.f <<= 1; - --value.e; - } - // Subtract 1 to account for hidden bit. - const auto offset = - fp::significand_size - fp::double_significand_size - SHIFT - 1; - value.f <<= offset; - value.e -= offset; - return value; - } - // Assigns d to this and return true iff predecessor is closer than successor. template bool assign(Double d) { @@ -434,6 +417,22 @@ class fp { } }; +// Normalizes the value converted from double and multiplied by (1 << SHIFT). +template fp normalize(fp value) { + // Handle subnormals. + const auto shifted_implicit_bit = fp::implicit_bit << SHIFT; + while ((value.f & shifted_implicit_bit) == 0) { + value.f <<= 1; + --value.e; + } + // Subtract 1 to account for hidden bit. + const auto offset = + fp::significand_size - fp::double_significand_size - SHIFT - 1; + value.f <<= offset; + value.e -= offset; + return value; +} + inline bool operator==(fp x, fp y) { return x.f == y.f && x.e == y.e; } // Computes lhs * rhs / pow(2, 64) rounded to nearest with half-up tie breaking.