Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
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 {returnPyFloat_AsDouble(op); }}
So, we assume instead that theop is a float-like class (a subtype of or something with a__float__ dunder method). Instead, we should look on the__complex__ method in theelse branch. This is an issue like#44670, I think.
Minor issue: these functions aren't tested, only indirectly withformat() (that will not trigger all possible cases).
Edit:
The currentPyComplex_ImagAsDouble() silently returns0.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.