From 90ef46df0be458c08db60ff4ead12917ef14b31c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 28 Sep 2020 18:10:46 -0700 Subject: [PATCH] Fix dragonbox integration --- include/fmt/format-inl.h | 4 ++++ test/format-test.cc | 2 ++ 2 files changed, 6 insertions(+) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index c1de4fa8..7ffda020 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2307,6 +2307,10 @@ FMT_SAFEBUFFERS decimal_fp to_decimal(T x) FMT_NOEXCEPT { goto small_divisor_case_label; } } + if (ret_value.significand == 0) { + ret_value.exponent = 0; + return ret_value; + } ret_value.exponent = minus_k + float_info::kappa + 1; // We may need to remove trailing zeros diff --git a/test/format-test.cc b/test/format-test.cc index 8cf54182..911d1d58 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1238,10 +1238,12 @@ TEST(FormatterTest, FormatConvertibleToLongLong) { } TEST(FormatterTest, FormatFloat) { + EXPECT_EQ("0", format("{}", 0.0f)); EXPECT_EQ("392.500000", format("{0:f}", 392.5f)); } TEST(FormatterTest, FormatDouble) { + EXPECT_EQ("0", format("{}", 0.0)); check_unknown_types(1.2, "eEfFgGaAnL%", "double"); EXPECT_EQ("0", format("{:}", 0.0)); EXPECT_EQ("0.000000", format("{:f}", 0.0));