Fix stdio fmt of "%.0e" and "%.0g" (#544)

* Fix %.0e by always rounding even if precision is 0
* Fix %.0g by treating it the same as %.1g
* Fix %g tests to match glibc, add more tests
This commit is contained in:
Gavin Hayes 2022-08-18 18:53:07 -04:00 committed by GitHub
parent 27416e7dd6
commit 897e33ccc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -335,10 +335,10 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
case 'G':
case 'g':
if (!(flags & FLAGS_PRECISION)) prec = 6;
if (prec < 0) prec = 0;
if (prec < 1) prec = 1;
if (!longdouble) {
x = va_arg(va, double);
s = s0 = dtoa(x, prec ? 2 : 0, prec, &decpt, &fpb.sign, &se);
s = s0 = dtoa(x, 2, prec, &decpt, &fpb.sign, &se);
if (decpt == 9999) {
if (s && s[0] == 'N') {
fpb.kind = STRTOG_NaN;
@ -379,7 +379,7 @@ int __fmt_dtoa(int (*out)(const char *, void *, size_t), void *arg, int d,
if (prec < 0) prec = 0;
if (!longdouble) {
x = va_arg(va, double);
s = s0 = dtoa(x, prec ? 2 : 0, prec + 1, &decpt, &fpb.sign, &se);
s = s0 = dtoa(x, 2, prec + 1, &decpt, &fpb.sign, &se);
if (decpt == 9999) {
if (s && s[0] == 'N') {
fpb.kind = STRTOG_NaN;