From 08a196697c5dfb8cbe3b3e85c1c5f94e3a27804c Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 4 Oct 2017 23:15:55 +1100 Subject: py/formatfloat: Don't print the negative sign of a NaN value. NaN may have the sign bit set but it has no meaning, so don't print it out. --- py/formatfloat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'py/formatfloat.c') diff --git a/py/formatfloat.c b/py/formatfloat.c index 35cd5d51a..b61a958a2 100644 --- a/py/formatfloat.c +++ b/py/formatfloat.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "py/formatfloat.h" /*********************************************************************** @@ -82,7 +83,6 @@ static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u < #define FPROUND_TO_ONE 0.999999999995 #define FPDECEXP 256 #define FPMIN_BUF_SIZE 7 // +9e+199 -#include #define fp_signbit(x) signbit(x) #define fp_isspecial(x) 1 #define fp_isnan(x) isnan(x) @@ -122,7 +122,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch } return buf_size >= 2; } - if (fp_signbit(f)) { + if (fp_signbit(f) && !isnan(f)) { *s++ = '-'; f = -f; } else { -- cgit v1.2.3