Skip to content

Commit

Permalink
Use p2197 format for complex by default
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut authored and happymonkey1 committed Apr 6, 2024
1 parent ebb271e commit 6b48271
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ struct formatter<std::complex<F>, Char> : nested_formatter<F, Char> {

template <typename OutputIt>
FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt {
auto format =
detail::string_literal<Char, '(', '{', '}', ',', '{', '}', ')'>{};
auto format = detail::string_literal<Char, '(', '{', '}', '+', '{', '}',
'i', ')'>{};
return fmt::format_to(out, basic_string_view<Char>(format),
f->nested(c.real()), f->nested(c.imag()));
}
Expand Down
4 changes: 2 additions & 2 deletions test/std-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ TEST(std_test, thread_id) {
}

TEST(std_test, complex) {
EXPECT_EQ(fmt::format("{}", std::complex<double>(1, 2.2)), "(1,2.2)");
EXPECT_EQ(fmt::format("{}", std::complex<double>(1, 2.2)), "(1+2.2i)");
EXPECT_EQ(fmt::format("{:>20.2f}", std::complex<double>(1, 2.2)),
" (1.00,2.20)");
" (1.00+2.20i)");
}

#ifdef __cpp_lib_source_location
Expand Down
6 changes: 3 additions & 3 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ TEST(locale_test, sign) {

TEST(std_test_xchar, complex) {
auto s = fmt::format(L"{}", std::complex<double>(1, 2));
EXPECT_EQ(s, L"(1,2)");
EXPECT_EQ(fmt::format(L"{:.2f}", std::complex<double>(1, 2)), L"(1.00,2.00)");
EXPECT_EQ(fmt::format(L"{:8}", std::complex<double>(1, 2)), L"(1,2) ");
EXPECT_EQ(s, L"(1+2i)");
EXPECT_EQ(fmt::format(L"{:.2f}", std::complex<double>(1, 2)), L"(1.00+2.00i)");
EXPECT_EQ(fmt::format(L"{:8}", std::complex<double>(1, 2)), L"(1+2i) ");
}

TEST(std_test_xchar, optional) {
Expand Down

0 comments on commit 6b48271

Please sign in to comment.