mirror of
https://github.com/fmtlib/fmt.git
synced 2024-09-03 13:39:15 +00:00
Workaround a double-double hexfloat format (#3366)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
bce8d4ed08
commit
97aedeab48
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user