@@ -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,11 +110,13 @@ 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)
@@ -121,7 +127,9 @@ Complex Numbers as Python Objects
121
127
:meth: `~object.__complex__ ` method, this method will first be called to
122
128
convert *op * to a Python complex number object. If :meth: `!__complex__ ` is
123
129
not defined then it falls back to call :c:func: `PyFloat_AsDouble ` and
124
- returns its result. Upon failure, this method returns ``-1.0 ``, so one
130
+ returns its result.
131
+
132
+ Upon failure, this method returns ``-1.0 `` with an exception set, so one
125
133
should call :c:func: `PyErr_Occurred ` to check for errors.
126
134
127
135
.. versionchanged :: 3.13
@@ -135,8 +143,10 @@ Complex Numbers as Python Objects
135
143
:meth: `~object.__complex__ ` method, this method will first be called to
136
144
convert *op * to a Python complex number object. If :meth: `!__complex__ ` is
137
145
not defined then it falls back to call :c:func: `PyFloat_AsDouble ` and
138
- returns ``0.0 `` on success. Upon failure, this method returns ``-1.0 ``, so
139
- one should call :c:func: `PyErr_Occurred ` to check for errors.
146
+ returns ``0.0 `` on success.
147
+
148
+ Upon failure, this method returns ``-1.0 `` with an exception set, so one
149
+ should call :c:func: `PyErr_Occurred ` to check for errors.
140
150
141
151
.. versionchanged :: 3.13
142
152
Use :meth: `~object.__complex__ ` if available.
@@ -149,8 +159,11 @@ Complex Numbers as Python Objects
149
159
method, this method will first be called to convert *op * to a Python complex
150
160
number object. If :meth: `!__complex__ ` is not defined then it falls back to
151
161
:meth: `~object.__float__ `. If :meth: `!__float__ ` is not defined then it falls back
152
- to :meth: `~object.__index__ `. Upon failure, this method returns ``-1.0 `` as a real
153
- value.
162
+ to :meth: `~object.__index__ `.
163
+
164
+ Upon failure, this method returns :c:type: `Py_complex `
165
+ with :c:member: `~Py_complex.real ` set to ``-1.0 `` and with an exception set, so one
166
+ should call :c:func: `PyErr_Occurred ` to check for errors.
154
167
155
168
.. versionchanged :: 3.8
156
169
Use :meth: `~object.__index__ ` if available.
0 commit comments