Loading CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ # cmake_minimum_required (VERSION 3.14) project (cppduals VERSION 0.7.2 VERSION 0.7.3 LANGUAGES C CXX ) include (GNUInstallDirs) Loading duals/dual +2 −2 Original line number Diff line number Diff line Loading @@ -1907,7 +1907,7 @@ struct fmt::formatter<duals::dual<T>,Char> : public fmt::formatter<T,Char> out = detail::write<Char>(out, x.dpart(), specs, ctx.locale()); } else { if (x.rpart() || !x.dpart()) out = detail::write<Char>(out, x.rpart(), specs, ctx.locale()); out = detail::write<Char>(out, x.rpart() ? x.rpart() : T(0), specs, ctx.locale()); if (x.dpart()) { if (x.rpart() && x.dpart() >= 0) specs.set_sign(sign::plus); Loading Loading @@ -1991,7 +1991,7 @@ struct fmt::formatter<std::complex<T>,Char> : public fmt::formatter<T,Char> base::format(x.imag(), ctx); } else { if (x.real() || !x.imag()) base::format(x.real(), ctx); base::format(x.real() ? x.real() : T(0), ctx); if (x.imag()) { if (x.real()) { // Format imaginary to temp buffer to strip sign Loading tests/test_fmt.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -156,6 +156,23 @@ TEST(libfmt, complex_plus) { s = fmt::format("{:+}", 1. - 3i); EXPECT_EQ(s, "(+1-3i)"); } TEST(libfmt, complex_neg_zero) { std::string s; s = fmt::format("{}", std::complex<double>(-0.0, 0.0)); EXPECT_EQ(s, "0") << "real=-0 should normalize to 0"; s = fmt::format("{}", std::complex<double>(0.0, -0.0)); EXPECT_EQ(s, "0") << "imag=-0 should normalize to 0"; s = fmt::format("{}", std::complex<double>(-0.0, -0.0)); EXPECT_EQ(s, "0") << "both=-0 should normalize to 0"; s = fmt::format("{}", std::complex<double>(-0.0, 3.0)); EXPECT_EQ(s, "3i") << "real=-0 should be suppressed"; s = fmt::format("{}", std::complex<double>(3.0, -0.0)); EXPECT_EQ(s, "3") << "imag=-0 should be suppressed"; } TEST(libfmt, complex_g) { std::string s = fmt::format("{:g}", 2.f + 3if); EXPECT_EQ(s, "(2+3if)"); Loading Loading @@ -232,6 +249,23 @@ TEST(libfmt, dual_flags) { s = fmt::format("{:,+}", 2. + 3_e); EXPECT_EQ(s, "(+2,+3)"); } TEST(libfmt, dual_neg_zero) { std::string s; s = fmt::format("{}", duals::duald(-0.0, 0.0)); EXPECT_EQ(s, "0") << "rpart=-0 should normalize to 0"; s = fmt::format("{}", duals::duald(0.0, -0.0)); EXPECT_EQ(s, "0") << "dpart=-0 should normalize to 0"; s = fmt::format("{}", duals::duald(-0.0, -0.0)); EXPECT_EQ(s, "0") << "both=-0 should normalize to 0"; s = fmt::format("{}", duals::duald(-0.0, 3.0)); EXPECT_EQ(s, "3_e") << "rpart=-0 should be suppressed"; s = fmt::format("{}", duals::duald(3.0, -0.0)); EXPECT_EQ(s, "3") << "dpart=-0 should be suppressed"; } TEST(libfmt, dual_all_real) { std::string s; Loading Loading
CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ # cmake_minimum_required (VERSION 3.14) project (cppduals VERSION 0.7.2 VERSION 0.7.3 LANGUAGES C CXX ) include (GNUInstallDirs) Loading
duals/dual +2 −2 Original line number Diff line number Diff line Loading @@ -1907,7 +1907,7 @@ struct fmt::formatter<duals::dual<T>,Char> : public fmt::formatter<T,Char> out = detail::write<Char>(out, x.dpart(), specs, ctx.locale()); } else { if (x.rpart() || !x.dpart()) out = detail::write<Char>(out, x.rpart(), specs, ctx.locale()); out = detail::write<Char>(out, x.rpart() ? x.rpart() : T(0), specs, ctx.locale()); if (x.dpart()) { if (x.rpart() && x.dpart() >= 0) specs.set_sign(sign::plus); Loading Loading @@ -1991,7 +1991,7 @@ struct fmt::formatter<std::complex<T>,Char> : public fmt::formatter<T,Char> base::format(x.imag(), ctx); } else { if (x.real() || !x.imag()) base::format(x.real(), ctx); base::format(x.real() ? x.real() : T(0), ctx); if (x.imag()) { if (x.real()) { // Format imaginary to temp buffer to strip sign Loading
tests/test_fmt.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -156,6 +156,23 @@ TEST(libfmt, complex_plus) { s = fmt::format("{:+}", 1. - 3i); EXPECT_EQ(s, "(+1-3i)"); } TEST(libfmt, complex_neg_zero) { std::string s; s = fmt::format("{}", std::complex<double>(-0.0, 0.0)); EXPECT_EQ(s, "0") << "real=-0 should normalize to 0"; s = fmt::format("{}", std::complex<double>(0.0, -0.0)); EXPECT_EQ(s, "0") << "imag=-0 should normalize to 0"; s = fmt::format("{}", std::complex<double>(-0.0, -0.0)); EXPECT_EQ(s, "0") << "both=-0 should normalize to 0"; s = fmt::format("{}", std::complex<double>(-0.0, 3.0)); EXPECT_EQ(s, "3i") << "real=-0 should be suppressed"; s = fmt::format("{}", std::complex<double>(3.0, -0.0)); EXPECT_EQ(s, "3") << "imag=-0 should be suppressed"; } TEST(libfmt, complex_g) { std::string s = fmt::format("{:g}", 2.f + 3if); EXPECT_EQ(s, "(2+3if)"); Loading Loading @@ -232,6 +249,23 @@ TEST(libfmt, dual_flags) { s = fmt::format("{:,+}", 2. + 3_e); EXPECT_EQ(s, "(+2,+3)"); } TEST(libfmt, dual_neg_zero) { std::string s; s = fmt::format("{}", duals::duald(-0.0, 0.0)); EXPECT_EQ(s, "0") << "rpart=-0 should normalize to 0"; s = fmt::format("{}", duals::duald(0.0, -0.0)); EXPECT_EQ(s, "0") << "dpart=-0 should normalize to 0"; s = fmt::format("{}", duals::duald(-0.0, -0.0)); EXPECT_EQ(s, "0") << "both=-0 should normalize to 0"; s = fmt::format("{}", duals::duald(-0.0, 3.0)); EXPECT_EQ(s, "3_e") << "rpart=-0 should be suppressed"; s = fmt::format("{}", duals::duald(3.0, -0.0)); EXPECT_EQ(s, "3") << "dpart=-0 should be suppressed"; } TEST(libfmt, dual_all_real) { std::string s; Loading