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!