diff --git a/include/fmt/format.h b/include/fmt/format.h index 3961ded3..161df54a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3522,8 +3522,13 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt { } else { *ptr++ = static_cast('0' + significand); } - memcpy(ptr, prefix, 2); - ptr += 2; + if (std::is_same::value) { + memcpy(ptr, prefix, 2); + ptr += 2; + } else { + *ptr++ = prefix[0]; + *ptr++ = prefix[1]; + } if (abs_exponent >= 100) { *ptr++ = static_cast('0' + abs_exponent / 100); abs_exponent %= 100; diff --git a/test/xchar-test.cc b/test/xchar-test.cc index a94c1bd2..a823ca06 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -74,6 +74,7 @@ TEST(xchar_test, format_explicitly_convertible_to_wstring_view) { TEST(xchar_test, format) { EXPECT_EQ(fmt::format(L"{}", 42), L"42"); EXPECT_EQ(fmt::format(L"{}", 4.2), L"4.2"); + EXPECT_EQ(fmt::format(L"{}", 1e100), L"1e+100"); EXPECT_EQ(fmt::format(L"{}", L"abc"), L"abc"); EXPECT_EQ(fmt::format(L"{}", L'z'), L"z"); EXPECT_THROW(fmt::format(fmt::runtime(L"{:*\x343E}"), 42), fmt::format_error);