Commit 77d6036c authored by Alex Alabuzhev's avatar Alex Alabuzhev Committed by Victor Zverovich

Fix unexpected trailing decimal point (#1153)

parent ccc318e8
...@@ -1187,12 +1187,14 @@ It grisu_prettify(const char* digits, int size, int exp, It it, ...@@ -1187,12 +1187,14 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
} else if (full_exp > 0) { } else if (full_exp > 0) {
// 1234e-2 -> 12.34[0+] // 1234e-2 -> 12.34[0+]
it = copy_str<Char>(digits, digits + full_exp, it); it = copy_str<Char>(digits, digits + full_exp, it);
*it++ = static_cast<Char>('.');
if (!params.trailing_zeros) { if (!params.trailing_zeros) {
// Remove trailing zeros. // Remove trailing zeros.
while (size > full_exp && digits[size - 1] == '0') --size; while (size > full_exp && digits[size - 1] == '0') --size;
if (size != full_exp)
*it++ = static_cast<Char>('.');
return copy_str<Char>(digits + full_exp, digits + size, it); return copy_str<Char>(digits + full_exp, digits + size, it);
} }
*it++ = static_cast<Char>('.');
it = copy_str<Char>(digits + full_exp, digits + size, it); it = copy_str<Char>(digits + full_exp, digits + size, it);
if (params.num_digits > size) { if (params.num_digits > size) {
// Add trailing zeros. // Add trailing zeros.
......
...@@ -406,6 +406,8 @@ TEST(PrintfTest, Float) { ...@@ -406,6 +406,8 @@ TEST(PrintfTest, Float) {
EXPECT_PRINTF(buffer, "%E", 392.65); EXPECT_PRINTF(buffer, "%E", 392.65);
EXPECT_PRINTF("392.65", "%g", 392.65); EXPECT_PRINTF("392.65", "%g", 392.65);
EXPECT_PRINTF("392.65", "%G", 392.65); EXPECT_PRINTF("392.65", "%G", 392.65);
EXPECT_PRINTF("392", "%g", 392.0);
EXPECT_PRINTF("392", "%G", 392.0);
safe_sprintf(buffer, "%a", -392.65); safe_sprintf(buffer, "%a", -392.65);
EXPECT_EQ(buffer, format("{:a}", -392.65)); EXPECT_EQ(buffer, format("{:a}", -392.65));
safe_sprintf(buffer, "%A", -392.65); safe_sprintf(buffer, "%A", -392.65);
......
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