diff --git a/os/hal/lib/streams/chprintf.c b/os/hal/lib/streams/chprintf.c index 4ecec7bcff..1d0398a55d 100644 --- a/os/hal/lib/streams/chprintf.c +++ b/os/hal/lib/streams/chprintf.c @@ -35,6 +35,7 @@ #define MAX_FILLER 11 #define FLOAT_PRECISION 9 +// returns pointer behind produced string static char *long_to_string_with_divisor(char *p, long num, unsigned radix, @@ -79,9 +80,18 @@ static const long pow10[FLOAT_PRECISION] = { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; -static char *ftoa(char *p, double num, unsigned long precision) { +#define rusefi_cisnan(f) (*(((int*) (&f))) == 0x7FC00000) + +static char *ftoa(char *p, float num, unsigned long precision) { long l; + if (rusefi_cisnan(num)) { + *p ++ = 'N'; + *p ++ = 'a'; + *p ++ = 'N'; + return p; + } + if ((precision == 0) || (precision > FLOAT_PRECISION)) { precision = FLOAT_PRECISION; } @@ -140,13 +150,13 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { if (c == 0) { return n; } - + if (c != '%') { streamPut(chp, (uint8_t)c); n++; continue; } - + p = tmpbuf; s = tmpbuf; @@ -170,7 +180,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { fmt++; filler = '0'; } - + /* Width modifier.*/ if ( *fmt == '*') { width = va_arg(ap, int); @@ -193,7 +203,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { } } } - + /* Precision modifier.*/ precision = 0; if (c == '.') { @@ -216,7 +226,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { } } } - + /* Long modifier.*/ if (c == 'l' || c == 'L') { is_long = true;