Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions os/hal/lib/streams/chprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -193,7 +203,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
}
}
}

/* Precision modifier.*/
precision = 0;
if (c == '.') {
Expand All @@ -216,7 +226,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
}
}
}

/* Long modifier.*/
if (c == 'l' || c == 'L') {
is_long = true;
Expand Down