We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 81a06d2 commit 08a1966Copy full SHA for 08a1966
3 files changed
py/formatfloat.c
@@ -30,6 +30,7 @@
30
#include <assert.h>
31
#include <stdlib.h>
32
#include <stdint.h>
33
+#include <math.h>
34
#include "py/formatfloat.h"
35
36
/***********************************************************************
@@ -82,7 +83,6 @@ static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u <
82
83
#define FPROUND_TO_ONE 0.999999999995
84
#define FPDECEXP 256
85
#define FPMIN_BUF_SIZE 7 // +9e+199
-#include <math.h>
86
#define fp_signbit(x) signbit(x)
87
#define fp_isspecial(x) 1
88
#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
122
}
123
return buf_size >= 2;
124
125
- if (fp_signbit(f)) {
+ if (fp_signbit(f) && !isnan(f)) {
126
*s++ = '-';
127
f = -f;
128
} else {
tests/float/complex1.py
@@ -59,6 +59,7 @@
59
60
# check printing of inf/nan
61
print(float('nan') * 1j)
62
+print(float('-nan') * 1j)
63
print(float('inf') * (1 + 1j))
64
print(float('-inf') * (1 + 1j))
65
tests/float/float1.py
@@ -21,6 +21,7 @@
21
print(float("infinity"))
22
print(float("INFINITY"))
23
print(float("nan"))
24
+print(float("-nan"))
25
print(float("NaN"))
26
try:
27
float("")
0 commit comments