Skip to content

Commit c7c08ff

Browse files
committed
cleanup and comments
1 parent a7f5ed9 commit c7c08ff

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Objects/floatobject.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ PyFloat_Pack2(double x, char *data, int le)
20542054
uint64_t v;
20552055

20562056
memcpy(&v, &x, sizeof(v));
2057-
bits = ((v & 0xffc0000000000ULL)>>42); /* NaN's payload */
2057+
bits = (v & 0xffc0000000000ULL) >> 42; /* NaN's payload */
20582058
}
20592059
else {
20602060
sign = (x < 0.0);
@@ -2218,14 +2218,15 @@ PyFloat_Pack4(double x, char *data, int le)
22182218
if (isinf(y) && !isinf(x))
22192219
goto Overflow;
22202220

2221+
/* correct y if x was a sNaN, transformed to qNaN by assignment */
22212222
if (isnan(x)) {
22222223
uint64_t v;
22232224

22242225
memcpy(&v, &x, 8);
2225-
if ((v & (1ULL<<51)) == 0) {
2226+
if ((v & (1ULL << 51)) == 0) {
22262227
uint32_t *py = (uint32_t *)&y;
22272228

2228-
*py -= (1<<22);
2229+
*py -= 1 << 22; /* make sNaN */
22292230
}
22302231
}
22312232

@@ -2413,7 +2414,7 @@ PyFloat_Unpack2(const char *data, int le)
24132414
/* NaN */
24142415
uint64_t v = sign ? 0xfff0000000000000ULL : 0x7ff0000000000000ULL;
24152416

2416-
v += ((uint64_t)f << 42); /* add NaN's payload */
2417+
v += (uint64_t)f << 42; /* add NaN's payload */
24172418
memcpy(&x, &v, sizeof(v));
24182419
return x;
24192420
}
@@ -2511,15 +2512,16 @@ PyFloat_Unpack4(const char *data, int le)
25112512
memcpy(&x, p, 4);
25122513
}
25132514

2515+
/* return sNaN double if x was sNaN float */
25142516
if (isnan(x)) {
25152517
uint32_t v;
25162518

25172519
memcpy(&v, &x, 4);
25182520
if ((v & (1<<22)) == 0) {
2519-
double y = x;
2521+
double y = x; /* will make qNaN double */
25202522
uint64_t *py = (uint64_t *)&y;
25212523

2522-
*py -= (1ULL<<51);
2524+
*py -= (1ULL<<51); /* make sNaN */
25232525
return y;
25242526
}
25252527
}

0 commit comments

Comments
 (0)