prf.c: handle denormals properly
Denormals need to be normalized to be displayed properly. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
53169743d2
commit
3c0cc08657
2 changed files with 13 additions and 0 deletions
|
@ -263,6 +263,12 @@ static int _to_float(char *buf, uint64_t double_temp, char c,
|
|||
}
|
||||
|
||||
if ((exp | fract) != 0) {
|
||||
if (exp == 0) {
|
||||
/* this is a denormal */
|
||||
while (((fract <<= 1) & HIGHBIT64) == 0) {
|
||||
exp--;
|
||||
}
|
||||
}
|
||||
exp -= (1023 - 1); /* +1 since .1 vs 1. */
|
||||
fract |= HIGHBIT64;
|
||||
}
|
||||
|
|
|
@ -322,6 +322,13 @@ void test_sprintf_double(void)
|
|||
zassert_true((strcmp(buffer, "0.0001505") == 0),
|
||||
"sprintf(0.0001505) - incorrect "
|
||||
"output '%s'\n", buffer);
|
||||
|
||||
var.u1 = 0x00000001;
|
||||
var.u2 = 0x00000000; /* smallest denormal value */
|
||||
sprintf(buffer, "%g", var.d);
|
||||
zassert_true((strcmp(buffer, "4.94066e-324") == 0),
|
||||
"sprintf(4.94066e-324) - incorrect "
|
||||
"output '%s'\n", buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue