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.
This commit is contained in:
parent
81a06d2c9c
commit
08a196697c
|
@ -30,6 +30,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <math.h>
|
||||||
#include "py/formatfloat.h"
|
#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 FPROUND_TO_ONE 0.999999999995
|
||||||
#define FPDECEXP 256
|
#define FPDECEXP 256
|
||||||
#define FPMIN_BUF_SIZE 7 // +9e+199
|
#define FPMIN_BUF_SIZE 7 // +9e+199
|
||||||
#include <math.h>
|
|
||||||
#define fp_signbit(x) signbit(x)
|
#define fp_signbit(x) signbit(x)
|
||||||
#define fp_isspecial(x) 1
|
#define fp_isspecial(x) 1
|
||||||
#define fp_isnan(x) isnan(x)
|
#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;
|
return buf_size >= 2;
|
||||||
}
|
}
|
||||||
if (fp_signbit(f)) {
|
if (fp_signbit(f) && !isnan(f)) {
|
||||||
*s++ = '-';
|
*s++ = '-';
|
||||||
f = -f;
|
f = -f;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -59,6 +59,7 @@ ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag))
|
||||||
|
|
||||||
# check printing of inf/nan
|
# check printing of inf/nan
|
||||||
print(float('nan') * 1j)
|
print(float('nan') * 1j)
|
||||||
|
print(float('-nan') * 1j)
|
||||||
print(float('inf') * (1 + 1j))
|
print(float('inf') * (1 + 1j))
|
||||||
print(float('-inf') * (1 + 1j))
|
print(float('-inf') * (1 + 1j))
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ print(float("INF"))
|
||||||
print(float("infinity"))
|
print(float("infinity"))
|
||||||
print(float("INFINITY"))
|
print(float("INFINITY"))
|
||||||
print(float("nan"))
|
print(float("nan"))
|
||||||
|
print(float("-nan"))
|
||||||
print(float("NaN"))
|
print(float("NaN"))
|
||||||
try:
|
try:
|
||||||
float("")
|
float("")
|
||||||
|
|
Loading…
Reference in New Issue