printf: Add support for %f
This commit is contained in:
parent
d2532efb83
commit
320e766ee1
40
src/printf.c
40
src/printf.c
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue