GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||
GeezerVison is showing github.com — gh-146151: memoryview supports 'F' and 'D' format types (complex) by skirpichev · Pull Request #146241 · python/cpython Conversation
|
| memcpy(ptr, &x, sizeof(x)); | ||
| } | ||
| else { | ||
| float x[2] = {(float)c.real, (float)c.imag}; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The behavior here is same as for 'f' format, just component-wise, see PACK_SINGLE macro.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…e-146151.4-lhim.rst Co-authored-by: Victor Stinner <[email protected]>
There was an error while loading. Please reload this page.
|
Merged, thanks for your contribution. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…x) (python#146241) Co-authored-by: Victor Stinner <[email protected]>
… (complex) (python#146241)" This reverts commit c68a194.
…x) (python#146241) Co-authored-by: Victor Stinner <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.