Workaround a double-double hexfloat format (#3366)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov 2023-04-01 19:19:23 +05:00 committed by GitHub
parent bce8d4ed08
commit 97aedeab48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -3344,7 +3344,7 @@ FMT_CONSTEXPR20 inline void format_dragon(basic_fp<uint128_t> value,
}
// Formats a floating-point number using the hexfloat format.
template <typename Float>
template <typename Float, FMT_ENABLE_IF(!is_double_double<Float>::value)>
FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision,
float_specs specs, buffer<char>& 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<char>(appender(buf), abs_e, detail::count_digits(abs_e));
}
template <typename Float, FMT_ENABLE_IF(is_double_double<Float>::value)>
FMT_CONSTEXPR20 void format_hexfloat(Float value, int precision,
float_specs specs, buffer<char>& buf) {
format_hexfloat(static_cast<double>(value), precision, specs, buf);
}
template <typename Float>
FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs,
buffer<char>& buf) -> int {

View File

@ -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<decltype(ld)>::value) {
safe_sprintf(buffer, "%a", static_cast<double>(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) {