gh-146151: memoryview supports 'F' and 'D' format types (complex)#146241
Open
skirpichev wants to merge 5 commits intopython:mainfrom
Open
gh-146151: memoryview supports 'F' and 'D' format types (complex)#146241skirpichev wants to merge 5 commits intopython:mainfrom
skirpichev wants to merge 5 commits intopython:mainfrom
Conversation
vstinner
reviewed
Mar 25, 2026
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
approved these changes
Mar 26, 2026
Member
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}; |
Member
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:
>>> import struct, 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.
Member
Author
There was a problem hiding this comment.
The behavior here is same as for 'f' format, just component-wise, see PACK_SINGLE macro.
Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-11-58.gh-issue-146151.4-lhim.rst
Outdated
Show resolved
Hide resolved
…e-146151.4-lhim.rst Co-authored-by: Victor Stinner <vstinner@python.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Documentation preview 📚: https://cpython-previews--146241.org.readthedocs.build/