mirror of
https://github.com/pocketpy/pocketpy
synced 2026-08-06 14:17:11 +08:00
abs(-0.0) returns -0.0 instead of 0.0, and math.fabs(-0.0) does the same. Both come from the idiom (x < 0) ? -x : x. Since -0.0 < 0 is false, the negative zero is returned unchanged. The idiom appears twice, once in dmath_fabs and once open-coded in float__abs__. Fix dmath_fabs by clearing the sign bit, the same way dmath_copysign just above it works, and make float__abs__ call the shared helper instead of repeating the comparison. abs(-0.0) == 0.0 is true even with the bug, because -0.0 == 0.0 under IEEE 754, so the added tests compare str(...) to check the sign.