/src/cpython/Objects/clinic/complexobject.c.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_modsupport.h" // _PyArg_BadArgument() |
10 | | |
11 | | PyDoc_STRVAR(complex_conjugate__doc__, |
12 | | "conjugate($self, /)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j."); |
16 | | |
17 | | #define COMPLEX_CONJUGATE_METHODDEF \ |
18 | | {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS, complex_conjugate__doc__}, |
19 | | |
20 | | static PyObject * |
21 | | complex_conjugate_impl(PyComplexObject *self); |
22 | | |
23 | | static PyObject * |
24 | | complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) |
25 | 0 | { |
26 | 0 | return complex_conjugate_impl((PyComplexObject *)self); |
27 | 0 | } |
28 | | |
29 | | PyDoc_STRVAR(complex___getnewargs____doc__, |
30 | | "__getnewargs__($self, /)\n" |
31 | | "--\n" |
32 | | "\n"); |
33 | | |
34 | | #define COMPLEX___GETNEWARGS___METHODDEF \ |
35 | | {"__getnewargs__", (PyCFunction)complex___getnewargs__, METH_NOARGS, complex___getnewargs____doc__}, |
36 | | |
37 | | static PyObject * |
38 | | complex___getnewargs___impl(PyComplexObject *self); |
39 | | |
40 | | static PyObject * |
41 | | complex___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
42 | 0 | { |
43 | 0 | return complex___getnewargs___impl((PyComplexObject *)self); |
44 | 0 | } |
45 | | |
46 | | PyDoc_STRVAR(complex___format____doc__, |
47 | | "__format__($self, format_spec, /)\n" |
48 | | "--\n" |
49 | | "\n" |
50 | | "Convert to a string according to format_spec."); |
51 | | |
52 | | #define COMPLEX___FORMAT___METHODDEF \ |
53 | | {"__format__", (PyCFunction)complex___format__, METH_O, complex___format____doc__}, |
54 | | |
55 | | static PyObject * |
56 | | complex___format___impl(PyComplexObject *self, PyObject *format_spec); |
57 | | |
58 | | static PyObject * |
59 | | complex___format__(PyObject *self, PyObject *arg) |
60 | 0 | { |
61 | 0 | PyObject *return_value = NULL; |
62 | 0 | PyObject *format_spec; |
63 | |
|
64 | 0 | if (!PyUnicode_Check(arg)) { |
65 | 0 | _PyArg_BadArgument("__format__", "argument", "str", arg); |
66 | 0 | goto exit; |
67 | 0 | } |
68 | 0 | format_spec = arg; |
69 | 0 | return_value = complex___format___impl((PyComplexObject *)self, format_spec); |
70 | |
|
71 | 0 | exit: |
72 | 0 | return return_value; |
73 | 0 | } |
74 | | |
75 | | PyDoc_STRVAR(complex___complex____doc__, |
76 | | "__complex__($self, /)\n" |
77 | | "--\n" |
78 | | "\n" |
79 | | "Convert this value to exact type complex."); |
80 | | |
81 | | #define COMPLEX___COMPLEX___METHODDEF \ |
82 | | {"__complex__", (PyCFunction)complex___complex__, METH_NOARGS, complex___complex____doc__}, |
83 | | |
84 | | static PyObject * |
85 | | complex___complex___impl(PyComplexObject *self); |
86 | | |
87 | | static PyObject * |
88 | | complex___complex__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
89 | 0 | { |
90 | 0 | return complex___complex___impl((PyComplexObject *)self); |
91 | 0 | } |
92 | | |
93 | | PyDoc_STRVAR(complex_new__doc__, |
94 | | "complex(real=0, imag=0)\n" |
95 | | "--\n" |
96 | | "\n" |
97 | | "Create a complex number from a string or numbers.\n" |
98 | | "\n" |
99 | | "If a string is given, parse it as a complex number.\n" |
100 | | "If a single number is given, convert it to a complex number.\n" |
101 | | "If the \'real\' or \'imag\' arguments are given, create a complex number\n" |
102 | | "with the specified real and imaginary components."); |
103 | | |
104 | | static PyObject * |
105 | | complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i); |
106 | | |
107 | | static PyObject * |
108 | | complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
109 | 0 | { |
110 | 0 | PyObject *return_value = NULL; |
111 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
112 | |
|
113 | 0 | #define NUM_KEYWORDS 2 |
114 | 0 | static struct { |
115 | 0 | PyGC_Head _this_is_not_used; |
116 | 0 | PyObject_VAR_HEAD |
117 | 0 | Py_hash_t ob_hash; |
118 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
119 | 0 | } _kwtuple = { |
120 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
121 | 0 | .ob_hash = -1, |
122 | 0 | .ob_item = { &_Py_ID(real), &_Py_ID(imag), }, |
123 | 0 | }; |
124 | 0 | #undef NUM_KEYWORDS |
125 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
126 | |
|
127 | | #else // !Py_BUILD_CORE |
128 | | # define KWTUPLE NULL |
129 | | #endif // !Py_BUILD_CORE |
130 | |
|
131 | 0 | static const char * const _keywords[] = {"real", "imag", NULL}; |
132 | 0 | static _PyArg_Parser _parser = { |
133 | 0 | .keywords = _keywords, |
134 | 0 | .fname = "complex", |
135 | 0 | .kwtuple = KWTUPLE, |
136 | 0 | }; |
137 | 0 | #undef KWTUPLE |
138 | 0 | PyObject *argsbuf[2]; |
139 | 0 | PyObject * const *fastargs; |
140 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
141 | 0 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
142 | 0 | PyObject *r = NULL; |
143 | 0 | PyObject *i = NULL; |
144 | |
|
145 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
146 | 0 | /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
147 | 0 | if (!fastargs) { |
148 | 0 | goto exit; |
149 | 0 | } |
150 | 0 | if (!noptargs) { |
151 | 0 | goto skip_optional_pos; |
152 | 0 | } |
153 | 0 | if (fastargs[0]) { |
154 | 0 | r = fastargs[0]; |
155 | 0 | if (!--noptargs) { |
156 | 0 | goto skip_optional_pos; |
157 | 0 | } |
158 | 0 | } |
159 | 0 | i = fastargs[1]; |
160 | 0 | skip_optional_pos: |
161 | 0 | return_value = complex_new_impl(type, r, i); |
162 | |
|
163 | 0 | exit: |
164 | 0 | return return_value; |
165 | 0 | } |
166 | | |
167 | | PyDoc_STRVAR(complex_from_number__doc__, |
168 | | "from_number($type, number, /)\n" |
169 | | "--\n" |
170 | | "\n" |
171 | | "Convert number to a complex floating-point number."); |
172 | | |
173 | | #define COMPLEX_FROM_NUMBER_METHODDEF \ |
174 | | {"from_number", (PyCFunction)complex_from_number, METH_O|METH_CLASS, complex_from_number__doc__}, |
175 | | |
176 | | static PyObject * |
177 | | complex_from_number_impl(PyTypeObject *type, PyObject *number); |
178 | | |
179 | | static PyObject * |
180 | | complex_from_number(PyObject *type, PyObject *number) |
181 | 0 | { |
182 | 0 | PyObject *return_value = NULL; |
183 | |
|
184 | 0 | return_value = complex_from_number_impl((PyTypeObject *)type, number); |
185 | |
|
186 | 0 | return return_value; |
187 | 0 | } |
188 | | /*[clinic end generated code: output=05d2ff43fc409733 input=a9049054013a1b77]*/ |