Fix floating point printing of negative numbers in the range (0, -1.0)
This commit is contained in:
parent
aca141269e
commit
49b5533000
16
stm/printf.c
16
stm/printf.c
@ -219,9 +219,19 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
|
||||
mp_float_t d = va_arg(args, double);
|
||||
int left = (int)d;
|
||||
int right = (int)((d - (mp_float_t)(int)d) * 1000000.0);
|
||||
chrs += pfenv_print_int(pfenv, left, 1, 10, 'a', flags, width);
|
||||
chrs += pfenv_print_strn(pfenv, &dot, 1, flags, width);
|
||||
chrs += pfenv_print_int(pfenv, right, 0, 10, 'a', PF_FLAG_ZERO_PAD, 6);
|
||||
if (right < 0) {
|
||||
if (left == 0) {
|
||||
chrs += pfenv_print_strn(pfenv, "-0", 2, flags, width);
|
||||
} else {
|
||||
chrs += pfenv_print_int(pfenv, left, 1, 10, 'a', flags, width);
|
||||
}
|
||||
chrs += pfenv_print_strn(pfenv, &dot, 1, flags, width);
|
||||
chrs += pfenv_print_int(pfenv, -right, 0, 10, 'a', PF_FLAG_ZERO_PAD, 6);
|
||||
} else {
|
||||
chrs += pfenv_print_int(pfenv, left, 1, 10, 'a', flags, width);
|
||||
chrs += pfenv_print_strn(pfenv, &dot, 1, flags, width);
|
||||
chrs += pfenv_print_int(pfenv, right, 0, 10, 'a', PF_FLAG_ZERO_PAD, 6);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user