forked from len0rd/rockbox
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
This commit is contained in:
parent
a8423321b8
commit
01c6dcf6c7
1 changed files with 18 additions and 0 deletions
|
|
@ -524,6 +524,18 @@ static inline const char * format_p(const void *p,
|
||||||
}
|
}
|
||||||
#endif /* FMT_RADIX_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 */
|
/* parse fixed width or precision field */
|
||||||
static const char * parse_number_spec(const char *fmt,
|
static const char * parse_number_spec(const char *fmt,
|
||||||
int ch,
|
int ch,
|
||||||
|
|
@ -741,6 +753,12 @@ int vuprintf(vuprintf_push_cb push, /* call 'push()' for each output letter */
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
case 'g':
|
||||||
|
buf = format_f(va_arg(ap, double), &fmt_buf, ch,
|
||||||
|
&numeric);
|
||||||
|
break;
|
||||||
|
|
||||||
/** signed integer **/
|
/** signed integer **/
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'i':
|
case 'i':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue