Commit 946498cf authored by Victor Zverovich's avatar Victor Zverovich

Fix handling of zero precision

parent 6b208639
...@@ -610,7 +610,7 @@ struct fixed_handler { ...@@ -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
......
...@@ -52,3 +52,7 @@ TEST(GrisuTest, Prettify) { ...@@ -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));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment