From 2b3f3c13067f0f3f061dcfd7b59b925082e72d0d Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Tue, 21 Nov 2017 14:52:23 +0100 Subject: Removed ftoa NaN check NaN check may not work with optimizing compilers. Use your implementation specific NaN check if necessary --- printf.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/printf.c b/printf.c index fd29785..83c6d9e 100644 --- a/printf.c +++ b/printf.c @@ -214,7 +214,7 @@ static size_t _ntoa_long_long(char* buffer, unsigned long long value, bool negat static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec, unsigned int width, unsigned int flags) { char buf[FTOA_BUFFER_SIZE]; - size_t len = 0U; + size_t len = 0U; double diff = 0.0; // if input is larger than thres_max, revert to exponential @@ -223,10 +223,11 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec // powers of 10 static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; - // test for NaN - if (!(value == value) && (maxlen > 2U)) { - buffer[0] = 'n'; buffer[1] = 'a'; buffer[2] = 'n'; - return (size_t)3U; + // test for negative + bool negative = false; + if (value < 0) { + negative = true; + value = 0 - value; } // limit precision @@ -238,12 +239,6 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec prec = 9U; } - unsigned int negative = 0U; - if (value < 0) { - negative = 1U; - value = 0 - value; - } - int whole = (int)value; double tmp = (value - whole) * pow10[prec]; unsigned long frac = (unsigned long)tmp; -- cgit v1.2.3