print: fix hex padding (and add spaces)

This commit is contained in:
King Kévin 2020-06-24 11:49:52 +02:00
parent 8566a4043b
commit 60279d0a52
1 changed files with 6 additions and 3 deletions

View File

@ -142,14 +142,14 @@ static size_t print_float(char** str, size_t* size, double f, uint32_t padding,
if (isnan(f)) { // not a number
print_printed(&length, print_string(str, size, "NaN")); // print NaN
} else if (isinf(f)) { // infinite
if (-1==isinf(f)) {
if (-1 == isinf(f)) {
print_printed(&length, print_char(str, size, '-')); // print sign
} else if (sign) {
print_printed(&length, print_char(str, size, '+')); // print sign
}
print_printed(&length, print_string(str, size, "inf")); // print inf
} else if (isnormal(f)) { // it should be not 0
if (f<0) {
if (f < 0) {
print_printed(&length, print_char(str, size, '-')); // print sign
} else if (sign) {
print_printed(&length, print_char(str, size, '+')); // print sign
@ -192,7 +192,7 @@ static size_t print_float(char** str, size_t* size, double f, uint32_t padding,
print_printed(&length, print_char(str, size, 'E')); // print exponent mark
print_printed(&length, print_signed(str, size, exponent, 0, false));
}
} else { // f=0
} else { // f = 0
// print sign
if (f < 0) {
print_printed(&length, print_char(str, size, '-')); // print sign
@ -251,6 +251,9 @@ static size_t print_hex(char** str, size_t* size, uint64_t hex, uint32_t padding
}
}
if (0 == padding) {
padding = 1; // show at least one hex
}
for (uint32_t zeros = nibbles; zeros < padding; zeros++) { // print padding 0's
print_printed(&length, print_char(str, size, '0')); // print 0
}