Title: Make PyComplex_RealAsDouble/ImagAsDouble use __complex__ · Issue #109598 · python/cpython · GitHub
Open Graph Title: Make PyComplex_RealAsDouble/ImagAsDouble use __complex__ · Issue #109598 · python/cpython
X Title: Make PyComplex_RealAsDouble/ImagAsDouble use __complex__ · Issue #109598 · python/cpython
Description: The C-API docs says: "Return the real/imag part of op as a C double." But the real code looks like: PyComplex_RealAsDouble(PyObject *op) { if (PyComplex_Check(op)) { return ((PyComplexObject *)op)->cval.real; } else { return PyFloat_AsDo...
Open Graph Description: The C-API docs says: "Return the real/imag part of op as a C double." But the real code looks like: PyComplex_RealAsDouble(PyObject *op) { if (PyComplex_Check(op)) { return ((PyComplexObject *)op)-...
X Description: The C-API docs says: "Return the real/imag part of op as a C double." But the real code looks like: PyComplex_RealAsDouble(PyObject *op) { if (PyComplex_Check(op)) { return ((PyComplexObj...
Opengraph URL: https://github.com/python/cpython/issues/109598
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make PyComplex_RealAsDouble/ImagAsDouble use __complex__","articleBody":"The C-API docs says: \"Return the real/imag part of op as a C double.\" But the real code looks like:\r\n```c\r\nPyComplex_RealAsDouble(PyObject *op)\r\n{\r\n if (PyComplex_Check(op)) {\r\n return ((PyComplexObject *)op)-\u003ecval.real;\r\n }\r\n else {\r\n return PyFloat_AsDouble(op);\r\n }\r\n}\r\n```\r\nSo, we assume instead that the ``op`` is a float-like class (a subtype of or something with a ``__float__`` dunder method). Instead, we should look on the ``__complex__`` method in the ``else`` branch. This is an issue like #44670, I think.\r\n\r\nMinor issue: these functions aren't tested, only indirectly with ``format()`` (that will not trigger all possible cases).\r\n\r\nEdit:\r\nThe current ``PyComplex_ImagAsDouble()`` silently returns ``0.0`` for all non-PyComplexObject objects (or subtypes of). I think it's a bug and we should return ``-1.0`` instead and set the error indicator.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-109647\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/skirpichev","@type":"Person","name":"skirpichev"},"datePublished":"2023-09-20T06:07:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/109598/cpython/issues/109598"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:72f58323-f8b2-6ba8-f6c4-8dec3dafb22f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB32:2F0D9B:101FED1:169E277:696A4144 |
| html-safe-nonce | d487743df8209e611d1ed4941ab181e8dc8f11e2332a7c49ef98c4b727c068ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjMyOjJGMEQ5QjoxMDFGRUQxOjE2OUUyNzc6Njk2QTQxNDQiLCJ2aXNpdG9yX2lkIjoiNDkwOTA5MTc3MzYzNjgyMTMxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 155bbefb684924a4669b4860420838d324a0d4b0eeffb0b2a545e6b3bedee006 |
| hovercard-subject-tag | issue:1904222780 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/109598/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8fb03b9153c0c602d53b7528810b53fc569d05c9c9de743286c902f82b0485bb/python/cpython/issues/109598 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8fb03b9153c0c602d53b7528810b53fc569d05c9c9de743286c902f82b0485bb/python/cpython/issues/109598 |
| og:image:alt | The C-API docs says: "Return the real/imag part of op as a C double." But the real code looks like: PyComplex_RealAsDouble(PyObject *op) { if (PyComplex_Check(op)) { return ((PyComplexObject *)op)-... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | skirpichev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 13581a31d51edf4a3aca179e10890a4d4f9b6d76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width