Message263631
About the Python 2.7 behaviour:
>>> from math import copysign
>>> x = float("-nan")
>>> copysign(1.0, x)
1.0
I'd be interested to know what `struct.pack('<d', x)` shows in this case. I'd expect it to be '\x00\x00\x00\x00\x00\x00\xf8\xff', meaning that the `float` conversion has produced a value with its sign bit set, as expected, but `copysign` has failed to transfer that sign bit. That failure is somewhat expected: older versions of MSVC don't provide copysign, so it has to be emulated, and the emulation doesn't take the sign of NaNs into account. (Getting the sign of a NaN is awkward to do without a native copysign function.) It works as expected on OS X and Linux.
So that's a separate issue: copysign on Windows / Python 2.7 doesn't correctly handle the sign bit of a NaN. I agree that that's less than ideal, but I'm not sure whether it's worth fixing for Python 2.7. |
|
Date |
User |
Action |
Args |
2016-04-17 21:25:49 | mark.dickinson | set | recipients:
+ mark.dickinson, eric.smith, ahrvoje |
2016-04-17 21:25:49 | mark.dickinson | set | messageid: <1460928349.55.0.295695042001.issue26785@psf.upfronthosting.co.za> |
2016-04-17 21:25:49 | mark.dickinson | link | issue26785 messages |
2016-04-17 21:25:49 | mark.dickinson | create | |
|