From 510b64b946d75ea7512449da86c4ab5609c0c0e9 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 15 Feb 2013 09:57:29 +0800 Subject: [PATCH] Usermode/libc - Fixed itoa precision, ftoa rounding --- Usermode/Libraries/libc.so_src/printf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Usermode/Libraries/libc.so_src/printf.c b/Usermode/Libraries/libc.so_src/printf.c index 869ba227..f4b13a4a 100644 --- a/Usermode/Libraries/libc.so_src/printf.c +++ b/Usermode/Libraries/libc.so_src/printf.c @@ -417,7 +417,8 @@ size_t _printf_itoa(printf_putch_t putch_cb, void *putch_h, uint64_t num, tmpBuf[pos++] = map[ num % base ]; // Last digit of {number} // length of number, minus the sign character - PadLength -= pos - sign_is_neg - (SignChar != '\0'); + PadLength -= pos + (sign_is_neg || SignChar != '\0'); + Precision -= pos + (sign_is_neg || SignChar != '\0'); if( !bPadRight ) { while(PadLength-- > 0) @@ -680,6 +681,8 @@ size_t _printf_ftoa(printf_putch_t putch_cb, void *putch_h, long double num, siz _putch('+'); else { } + + num += precision_max/10 * 5; int value; // Whole section @@ -707,7 +710,7 @@ size_t _printf_ftoa(printf_putch_t putch_cb, void *putch_h, long double num, siz _putch('p'); else _putch('e'); - ret += _printf_itoa(putch_cb, putch_h, sci_exponent, Base, FALSE, TRUE, '+', 0, 0, '\0', FALSE); + ret += _printf_itoa(putch_cb, putch_h, sci_exponent, Base, FALSE, TRUE, '+', 3, 0, '\0', FALSE); } #undef _putch -- 2.20.1