diff --git a/include/fmt/format.h b/include/fmt/format.h index 1e18827ee83f..6680b380e012 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3344,7 +3344,7 @@ FMT_CONSTEXPR20 inline void format_dragon(basic_fp value, } // Formats a floating-point number using the hexfloat format. -template +template ::value)> FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision, float_specs specs, buffer& buf) { // float is passed as double to reduce the number of instantiations and to @@ -3425,6 +3425,12 @@ FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision, format_decimal(appender(buf), abs_e, detail::count_digits(abs_e)); } +template ::value)> +FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision, + float_specs specs, buffer& buf) { + format_hexfloat(static_cast(value), precision, specs, buf); +} + template FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs, buffer& buf) -> int { diff --git a/test/format-test.cc b/test/format-test.cc index 04e4798ef86c..b528986b3c02 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1489,8 +1489,15 @@ TEST(format_test, format_long_double) { safe_sprintf(buffer, "%Le", 392.65l); EXPECT_EQ(buffer, fmt::format("{0:e}", 392.65l)); EXPECT_EQ("+0000392.6", fmt::format("{0:+010.4g}", 392.64l)); - safe_sprintf(buffer, "%La", 3.31l); - EXPECT_EQ(buffer, fmt::format("{:a}", 3.31l)); + + auto ld = 3.31l; + if (fmt::detail::is_double_double::value) { + safe_sprintf(buffer, "%a", static_cast(ld)); + EXPECT_EQ(buffer, fmt::format("{:a}", ld)); + } else { + safe_sprintf(buffer, "%La", ld); + EXPECT_EQ(buffer, fmt::format("{:a}", ld)); + } } TEST(format_test, format_char) {