aboutsummaryrefslogtreecommitdiffstats
path: root/printf.c
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-04-20 13:28:55 +0200
committerMarco Paland <marco@paland.com>2018-04-20 13:28:55 +0200
commit85dc7cf0749661e799c488a515a12ab9353ee5b2 (patch)
treea9a24aa561b606481fc28e95593b6909adfd7f86 /printf.c
parent98e9b0dab6dd89537484f1e380c9e3c25c9761ca (diff)
downloadprintf-85dc7cf0749661e799c488a515a12ab9353ee5b2.tar.gz
printf-85dc7cf0749661e799c488a515a12ab9353ee5b2.tar.bz2
printf-85dc7cf0749661e799c488a515a12ab9353ee5b2.zip
fix(printf): fixed floating point sign handling
Diffstat (limited to 'printf.c')
-rw-r--r--printf.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/printf.c b/printf.c
index 69c7ea7..418386a 100644
--- a/printf.c
+++ b/printf.c
@@ -303,16 +303,16 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec
break;
}
}
-
+
// pad leading zeros
- while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
- buf[len++] = '0';
- }
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
// handle sign
+ if ((len == width) && (negative || (flags & FLAGS_PLUS) || (flags & FLAGS_SPACE))) {
+ len--;
+ }
if (len < PRINTF_FTOA_BUFFER_SIZE) {
if (negative) {
buf[len++] = '-';