diff --git a/newlib/libc/tinystdio/dtoa_ryu.c b/newlib/libc/tinystdio/dtoa_ryu.c index 2900d22bc1..486842e270 100644 --- a/newlib/libc/tinystdio/dtoa_ryu.c +++ b/newlib/libc/tinystdio/dtoa_ryu.c @@ -283,7 +283,7 @@ d2d(const uint64_t ieeeMantissa, const uint32_t ieeeExponent, int max_digits, bo // We need to take vr + 1 if vr is outside bounds or we need to round up. // I don't know if the 'truncate_max' case is entirely correct; need some tests - uint8_t carry = ((!truncate_max && vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || lastRemovedDigit >= 5); + uint8_t carry = (((!truncate_max && vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || lastRemovedDigit >= 5) && !(fmode && max_decimals == 0)); output += carry; int len = decimalLength17(output); diff --git a/test/testcases.c b/test/testcases.c index aa5f0a2b67..84ef3ff027 100644 --- a/test/testcases.c +++ b/test/testcases.c @@ -296,6 +296,7 @@ result |= test(__LINE__, "8.6000", "%2.4f", 8.6); result |= test(__LINE__, "0.600000", "%0f", 0.6); result |= test(__LINE__, "1", "%.0f", 0.6); + result |= test(__LINE__, "0", "%.0f", 0.45); result |= test(__LINE__, "8.6000e+00", "%2.4e", 8.6); result |= test(__LINE__, " 8.6000e+00", "% 2.4e", 8.6); result |= test(__LINE__, "-8.6000e+00", "% 2.4e", -8.6);