Fix handling of zero precision

This commit is contained in:
Victor Zverovich 2019-04-19 14:48:42 -07:00
parent 6b20863918
commit 946498cfbc
2 changed files with 5 additions and 1 deletions

View File

@ -610,7 +610,7 @@ struct fixed_handler {
uint64_t error, int, bool integral) { uint64_t error, int, bool integral) {
FMT_ASSERT(remainder < divisor, ""); FMT_ASSERT(remainder < divisor, "");
buf[size++] = digit; buf[size++] = digit;
if (size != precision) return digits::more; if (size < precision) return digits::more;
if (!integral) { if (!integral) {
// Check if error * 2 < divisor with overflow prevention. // Check if error * 2 < divisor with overflow prevention.
// The check is not needed for the integral part because error = 1 // The check is not needed for the integral part because error = 1

View File

@ -52,3 +52,7 @@ TEST(GrisuTest, Prettify) {
EXPECT_EQ("12.34", fmt::format("{}", 1234e-2)); EXPECT_EQ("12.34", fmt::format("{}", 1234e-2));
EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6)); EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6));
} }
TEST(GrisuTest, ZeroPrecision) {
EXPECT_EQ("1", fmt::format("{:.0}", 1.0));
}