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

2021-04-26 Thread Mark Dickinson
Mark Dickinson added the comment: > Is there any workaround? Sorry, I can't answer that without knowing what it is you're trying to do - that is, I don't know which part of the behaviour you want a workaround for. But that's getting off topic for this tracker, which is for bug reporting; I'd

[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 ___

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

2021-04-26 Thread Mark Dickinson
Change by Mark Dickinson : -- resolution: -> not a bug status: open -> pending ___ Python tracker ___ ___ Python-bugs-list mailing

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

2021-04-26 Thread Mark Dickinson
Mark Dickinson added the comment: There's an implicit float-to-double conversion here (`fp.contents.value` is represented as a Python float, which is backed by a C double). What you're seeing is that converting the single-precision signaling NaN to double precision loses the signaling bit, p

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

2021-04-25 Thread Steven D'Aprano
Steven D'Aprano added the comment: I believe that this may be the same issue as this thread https://mail.python.org/archives/list/python-...@python.org/thread/35NECLGFIVAHWTIPAYDBJOJJX3FSY233/ in particular this comment: https://mail.python.org/archives/list/python-...@python.org/message/QIC

[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.contents.value)) #'0x7fd4e5

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

2021-04-25 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +mark.dickinson, rhettinger, tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing l

[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 ___ ___

[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 changed: 7f94e57c -> 7fd4e57c -- compo