@@ -25,12 +25,16 @@ pointers. This is consistent throughout the API.
25
25
26
26
The C structure which corresponds to the value portion of a Python complex
27
27
number object. Most of the functions for dealing with complex number objects
28
- use structures of this type as input or output values, as appropriate. It is
29
- defined as::
28
+ use structures of this type as input or output values, as appropriate.
29
+
30
+ .. c :member :: double real
31
+ double imag
32
+
33
+ The structure is defined as::
30
34
31
35
typedef struct {
32
- double real;
33
- double imag;
36
+ double real;
37
+ double imag;
34
38
} Py_complex;
35
39
36
40
@@ -106,17 +110,22 @@ Complex Numbers as Python Objects
106
110
.. c :function :: PyObject* PyComplex_FromCComplex (Py_complex v)
107
111
108
112
Create a new Python complex number object from a C :c:type:`Py_complex` value.
113
+ Return ``NULL`` with an exception set on error.
109
114
110
115
111
116
.. c:function:: PyObject* PyComplex_FromDoubles(double real, double imag)
112
117
113
118
Return a new :c:type:`PyComplexObject` object from *real* and *imag*.
119
+ Return ``NULL`` with an exception set on error.
114
120
115
121
116
122
.. c:function:: double PyComplex_RealAsDouble(PyObject *op)
117
123
118
124
Return the real part of *op * as a C :c:expr: `double `.
119
125
126
+ Upon failure, this method returns ``-1.0 `` with an exception set, so one
127
+ should call :c:func: `PyErr_Occurred ` to check for errors.
128
+
120
129
121
130
.. c :function :: double PyComplex_ImagAsDouble (PyObject *op)
122
131
@@ -131,8 +140,11 @@ Complex Numbers as Python Objects
131
140
method, this method will first be called to convert *op * to a Python complex
132
141
number object. If :meth: `!__complex__ ` is not defined then it falls back to
133
142
:meth: `~object.__float__ `. If :meth: `!__float__ ` is not defined then it falls back
134
- to :meth: `~object.__index__ `. Upon failure, this method returns ``-1.0 `` as a real
135
- value.
143
+ to :meth: `~object.__index__ `.
144
+
145
+ Upon failure, this method returns :c:type: `Py_complex `
146
+ with :c:member: `~Py_complex.real ` set to ``-1.0 `` and with an exception set, so one
147
+ should call :c:func: `PyErr_Occurred ` to check for errors.
136
148
137
149
.. versionchanged :: 3.8
138
150
Use :meth: `~object.__index__ ` if available.
0 commit comments