libc: minimal: Fix support for -nan

We were only handling the sign bit for infinity, but not NaN.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2018-07-12 12:38:15 -05:00 committed by Kumar Gala
parent 96ea7ab7d1
commit 409c9e751f
2 changed files with 9 additions and 3 deletions

View file

@ -225,10 +225,10 @@ static int _to_float(char *buf, uint64_t double_temp, int c,
if (exp == 0x7ff) {
if (sign) {
*buf++ = '-';
}
if (!fract) {
if (sign) {
*buf++ = '-';
}
*buf++ = 'i';
*buf++ = 'n';
*buf++ = 'f';

View file

@ -89,6 +89,12 @@ void test_sprintf_double(void)
zassert_true((strcmp(buffer, "nan") == 0),
"sprintf(nan) - incorrect output '%s'\n", buffer);
var.u1 = 0x00000000;
var.u2 = 0xfff80000; /* Bit pattern for -NaN (double) */
sprintf(buffer, "%f", var.d);
zassert_true((strcmp(buffer, "-nan") == 0),
"sprintf(-nan) - incorrect output '%s'\n", buffer);
var.d = 1.0;
sprintf(buffer, "%f", var.d);
zassert_true((strcmp(buffer, "1.000000") == 0),