Uh oh!
There was an error while loading. Please reload this page.
gh-146151: memoryview supports 'F' and 'D' format types (complex) - #146241
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
left a comment
There was a problem hiding this comment.
LGTM. The implementation looks complete and well tested.
| memcpy(ptr, &x, sizeof(x)); | ||
| } | ||
| else { | ||
| float x[2] = {(float)c.real, (float)c.imag}; |
There was a problem hiding this comment.
I wasn't sure of the behavior on underflow or overflow of the double to float cast, so I tested:
>>>importstruct, sys>>>data=struct.pack('F', 0.0) *4>>>m=memoryview(bytearray(data)).cast('F')
>>>m[0]=math.nextafter(0, 1)
>>>m[1]=sys.float_info.min>>>m[2]=sys.float_info.max>>>m[3]=float("nan")
>>>m.tolist()
[0j, 0j, (inf+0j), (nan+0j)]I got the values that I expected. I suppose that these conversions are well specified by IEEE 754.
There was a problem hiding this comment.
The behavior here is same as for 'f' format, just component-wise, see PACK_SINGLE macro.
Uh oh!
There was an error while loading. Please reload this page.
…e-146151.4-lhim.rst Co-authored-by: Victor Stinner <vstinner@python.org>
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Mar 26, 2026
Merged, thanks for your contribution. |
…x) (python#146241) Co-authored-by: Victor Stinner <vstinner@python.org>
… (complex) (python#146241)" This reverts commit c68a194.
…x) (python#146241) Co-authored-by: Victor Stinner <vstinner@python.org>
📚 Documentation preview 📚: https://cpython-previews--146241.org.readthedocs.build/