Skip to content

Commit

Permalink
Merge pull request #1379 from IMRCLab/feature_print_nan
Browse files Browse the repository at this point in the history
printf: add support to print NaNs
  • Loading branch information
ataffanel committed Jun 3, 2024
2 parents 4a35997 + 3c64588 commit e6c4159
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/utils/src/eprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <ctype.h>
#include <math.h>

static const char digit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
Expand Down Expand Up @@ -275,15 +276,21 @@ int evprintf(putc_t putcf, const char * fmt, va_list ap)
break;
case 'f':
num = va_arg(ap, double);
if(num<0)
{
putcf('-');
num = -num;
len++;
if (isnan(num)) {
putcf('n');len++;
putcf('a');len++;
putcf('n');len++;
} else {
if(num<0)
{
putcf('-');
num = -num;
len++;
}
len += itoa10(putcf, (int)num, 0);
putcf('.'); len++;
len += itoa10(putcf, (num - (int)num) * power(10,precision), precision);
}
len += itoa10(putcf, (int)num, 0);
putcf('.'); len++;
len += itoa10(putcf, (num - (int)num) * power(10,precision), precision);
break;
case 's':
str = va_arg(ap, char* );
Expand Down

0 comments on commit e6c4159

Please sign in to comment.