[issue43940] int casting to float results to a different value in memory

2021-04-26 Thread Huang Yang
Huang Yang added the comment: OK. Seems it's the default behavior of CPU instruction. And CPU follows the IEEE standard of float. Is there any workaround? -- status: pending -> open ___ Python tracker <https://bugs.python.org

[issue43940] int casting to float results to a different value in memory

2021-04-25 Thread Huang Yang
Huang Yang added the comment: Also reproducible by: from ctypes import * i = int('7f94e57c', 16) cp = pointer(c_int(i)) fp = cast(cp, POINTER(c_float)) print(fp.contents.value) # nan p = pointer(c_float(fp.contents.value)) ip = cast(p, POINTER(c_int)) print(hex(ip.cont

[issue43940] int casting to float results to a different value in memory

2021-04-25 Thread Huang Yang
Huang Yang added the comment: It's reproducible only if the float is nan, with prefix 7f or ff. Seems the value is OR operated by 0x0040. -- ___ Python tracker <https://bugs.python.org/is

[issue43940] int casting to float results to a different value in memory

2021-04-25 Thread Huang Yang
New submission from Huang Yang : from ctypes import * import struct i = int('7f94e57c', 16) cp = pointer(c_int(i)) fp = cast(cp, POINTER(c_float)) print(fp.contents.value) # nan print(struct.pack(">f", fp.contents.value).hex()) # 7fd4e57c # value change