printf: Add support for %f

This commit is contained in:
Solomon Peachy 2019-11-29 19:07:47 -05:00
parent d2532efb83
commit 320e766ee1
1 changed files with 40 additions and 0 deletions

View File

@ -38,6 +38,46 @@ uint32_t parse_int(const char *src, int b, int width)
return val;
}
#ifdef WITH_FLOAT
static int __print_float(char *buf, int buf_len, float i, int width, int width2)
{
char *s, *p = buf;
uint8_t use_width = width;
uint8_t use_width2 = width2;
if (i == 0.0f) {
s = "0.0\0";
width--;
goto almost;
}
if (i < 0.0f) {
*buf++ = '-';
i = -i;
width--;
}
s = buf + buf_len - 1;
*s = '\0';
while (i != 0.0f && (!use_width || (width > 0))) {
t = (unsigned int) u % 10.0f;
*--s = (char)(t + '0');
u /= 10.0f;
width--;
}
almost:
while (width > 0) {
*buf++ = '0';
width--;
}
strcpy(buf, s);
return strlen(p);
}
#endif
static int __print_int(char *buf, int buf_len, int i, int base, int sign, int width)
{
char *s, *p = buf;