Mark Dickinson added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26785>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to