diff options
author | Franklin Wei <git@fwei.tk> | 2017-09-29 16:54:31 -0400 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-12-23 20:55:02 -0500 |
commit | 01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (patch) | |
tree | 28064ac51c2c150bb33a3f0f53db3771fc54fd3a | |
parent | a8423321b802bff39fe2ba22f2b0a26220a57535 (diff) | |
download | rockbox-01c6dcf.tar.gz rockbox-01c6dcf.zip |
Support floating-point formatting
This is just a quick and dirty way to get %f formatting to work for
some games. It works.
Change-Id: I75585e0c6a0f9d6db41a87b71ca405b067d8b85d
-rw-r--r-- | firmware/common/vuprintf.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/firmware/common/vuprintf.c b/firmware/common/vuprintf.c index c32b690cf8..1c0adad00e 100644 --- a/firmware/common/vuprintf.c +++ b/firmware/common/vuprintf.c @@ -524,6 +524,18 @@ static inline const char * format_p(const void *p, } #endif /* FMT_RADIX_p */ +#undef ABS +#define ABS(x) ((x)<0?-(x):(x)) + +static const char * format_f(double f, + struct fmt_buf *fmt_buf, + int radixchar, + bool *numericp) +{ + fmt_buf->length = snprintf(fmt_buf->buf, 24, "%d.%06d", (int)f, ABS((int)((f - (int)f)*1e6))); + return fmt_buf->buf; +} + /* parse fixed width or precision field */ static const char * parse_number_spec(const char *fmt, int ch, @@ -741,6 +753,12 @@ int vuprintf(vuprintf_push_cb push, /* call 'push()' for each output letter */ break; #endif + case 'f': + case 'g': + buf = format_f(va_arg(ap, double), &fmt_buf, ch, + &numeric); + break; + /** signed integer **/ case 'd': case 'i': |