Skip to content

Commit e4e0882

Browse files
committed
correct RISC-V workaround
1 parent 49741a8 commit e4e0882

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Objects/floatobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,9 +2216,6 @@ PyFloat_Pack4(double x, char *data, int le)
22162216
uint32_t u32;
22172217

22182218
memcpy(&u32, &y, 4);
2219-
if ((v & (1ULL << 51)) == 0 && (u32 & 0x3fffff)) {
2220-
u32 &= ~(1 << 22);
2221-
}
22222219
/* Workaround RISC-V: "If a NaN value is converted to a
22232220
* different floating-point type, the result is the
22242221
* canonical NaN of the new type". The canonical NaN here
@@ -2229,6 +2226,10 @@ PyFloat_Pack4(double x, char *data, int le)
22292226
/* add payload */
22302227
u32 -= (u32 & 0x3fffff);
22312228
u32 += (uint32_t)((v & 0x7ffffffffffffULL) >> 29);
2229+
/* if have payload, make sNaN */
2230+
if ((v & (1ULL << 51)) == 0 && (u32 & 0x3fffff)) {
2231+
u32 &= ~(1 << 22);
2232+
}
22322233

22332234
memcpy(&y, &u32, 4);
22342235
#endif

0 commit comments

Comments
 (0)