Hi, Code snippet 1 and 2 convert an hex to float, but the SNaN is changed to QNaN automatically. It follows IEEE 754 behavior. While Code snippet 3 converts an hex to double, and the SNaN keeps. Is there any solution to keep SNaN float unchanged in Code snippet 1 and 2?
1. >>> i = int('7f800001', 16) >>> cp = pointer(c_uint32(i)) >>> fp = cast(cp, POINTER(c_float)) >>> print(fp.contents.value) # nan >>> print(struct.pack(">f", fp.contents.value).hex()) 7fc00001 1. >>> f = struct.unpack('!f', bytes.fromhex('7f800001'))[0] >>> f # nan >>> hex(struct.unpack('<I', struct.pack('<f', f))[0]) '0x7fc00001' 1. >>> i = int('7FF0000000000001', 16) >>> cp = pointer(c_uint64(i)) >>> fp = cast(cp, POINTER(c_double)) >>> print(fp.contents.value) nan >>> print(struct.pack(">d", fp.contents.value).hex()) 7ff0000000000001 Thank you in advance!
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/BNVV6CWSHWLMBE2QJDZZ2N5VNJQAICT6/ Code of Conduct: http://python.org/psf/codeofconduct/