gh-130317: Fix test_pack_unpack_roundtrip() and add docs (#133204)

* Skip sNaN's testing in 32-bit mode.
* Drop float_set_snan() helper.
* Use memcpy() workaround for sNaN's in PyFloat_Unpack4().
* Document, that sNaN's may not be preserved by PyFloat_Pack/Unpack API.
This commit is contained in:
Sergey B Kirpichev 2025-05-01 17:20:36 +03:00 committed by GitHub
parent ed039b801d
commit ad2f0884b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 62 deletions

View file

@ -2495,12 +2495,10 @@ PyFloat_Unpack4(const char *data, int le)
if ((v & (1 << 22)) == 0) {
double y = x; /* will make qNaN double */
union double_val {
double d;
uint64_t u64;
} *py = (union double_val *)&y;
py->u64 &= ~(1ULL << 51); /* make sNaN */
uint64_t u64;
memcpy(&u64, &y, 8);
u64 &= ~(1ULL << 51); /* make sNaN */
memcpy(&y, &u64, 8);
return y;
}
}