Commit e7070085 authored by Damien George's avatar Damien George
Browse files

Merge pull request #323 from dhylands/fix-float-print

Fix floating point printing of negative numbers in the range (0, -1.0)
parents aca14126 49b55330
......@@ -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:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment