Skip to content

Commit dc948e4

Browse files
committed
py/formatfloat: Use standard isinf, isnan funcs instead of custom ones.
Reduces code size by a tiny bit.
1 parent 08a1966 commit dc948e4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

py/formatfloat.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ union floatbits {
6969
uint32_t u;
7070
};
7171
static inline int fp_signbit(float x) { union floatbits fb = {x}; return fb.u & FLT_SIGN_MASK; }
72-
static inline int fp_isspecial(float x) { union floatbits fb = {x}; return (fb.u & FLT_EXP_MASK) == FLT_EXP_MASK; }
73-
static inline int fp_isinf(float x) { union floatbits fb = {x}; return (fb.u & FLT_MAN_MASK) == 0; }
72+
#define fp_isnan(x) isnan(x)
73+
#define fp_isinf(x) isinf(x)
7474
static inline int fp_iszero(float x) { union floatbits fb = {x}; return fb.u == 0; }
7575
static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u < 0x3f800000; }
76-
// Assumes both fp_isspecial() and fp_isinf() were applied before
77-
#define fp_isnan(x) 1
7876

7977
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
8078

@@ -84,7 +82,6 @@ static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u <
8482
#define FPDECEXP 256
8583
#define FPMIN_BUF_SIZE 7 // +9e+199
8684
#define fp_signbit(x) signbit(x)
87-
#define fp_isspecial(x) 1
8885
#define fp_isnan(x) isnan(x)
8986
#define fp_isinf(x) isinf(x)
9087
#define fp_iszero(x) (x == 0)
@@ -122,7 +119,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
122119
}
123120
return buf_size >= 2;
124121
}
125-
if (fp_signbit(f) && !isnan(f)) {
122+
if (fp_signbit(f) && !fp_isnan(f)) {
126123
*s++ = '-';
127124
f = -f;
128125
} else {
@@ -135,7 +132,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
135132
// It is buf_size minus room for the sign and null byte.
136133
int buf_remaining = buf_size - 1 - (s - buf);
137134

138-
if (fp_isspecial(f)) {
135+
{
139136
char uc = fmt & 0x20;
140137
if (fp_isinf(f)) {
141138
*s++ = 'I' ^ uc;

0 commit comments

Comments
 (0)