1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(complex_conjugate__doc__,
6 "conjugate($self, /)\n"
7 "--\n"
8 "\n"
9 "Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.");
10 
11 #define COMPLEX_CONJUGATE_METHODDEF    \
12     {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS, complex_conjugate__doc__},
13 
14 static PyObject *
15 complex_conjugate_impl(PyComplexObject *self);
16 
17 static PyObject *
complex_conjugate(PyComplexObject * self,PyObject * Py_UNUSED (ignored))18 complex_conjugate(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
19 {
20     return complex_conjugate_impl(self);
21 }
22 
23 PyDoc_STRVAR(complex___getnewargs____doc__,
24 "__getnewargs__($self, /)\n"
25 "--\n"
26 "\n");
27 
28 #define COMPLEX___GETNEWARGS___METHODDEF    \
29     {"__getnewargs__", (PyCFunction)complex___getnewargs__, METH_NOARGS, complex___getnewargs____doc__},
30 
31 static PyObject *
32 complex___getnewargs___impl(PyComplexObject *self);
33 
34 static PyObject *
complex___getnewargs__(PyComplexObject * self,PyObject * Py_UNUSED (ignored))35 complex___getnewargs__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
36 {
37     return complex___getnewargs___impl(self);
38 }
39 
40 PyDoc_STRVAR(complex___format____doc__,
41 "__format__($self, format_spec, /)\n"
42 "--\n"
43 "\n"
44 "Convert to a string according to format_spec.");
45 
46 #define COMPLEX___FORMAT___METHODDEF    \
47     {"__format__", (PyCFunction)complex___format__, METH_O, complex___format____doc__},
48 
49 static PyObject *
50 complex___format___impl(PyComplexObject *self, PyObject *format_spec);
51 
52 static PyObject *
complex___format__(PyComplexObject * self,PyObject * arg)53 complex___format__(PyComplexObject *self, PyObject *arg)
54 {
55     PyObject *return_value = NULL;
56     PyObject *format_spec;
57 
58     if (!PyUnicode_Check(arg)) {
59         _PyArg_BadArgument("__format__", "argument", "str", arg);
60         goto exit;
61     }
62     if (PyUnicode_READY(arg) == -1) {
63         goto exit;
64     }
65     format_spec = arg;
66     return_value = complex___format___impl(self, format_spec);
67 
68 exit:
69     return return_value;
70 }
71 
72 PyDoc_STRVAR(complex___complex____doc__,
73 "__complex__($self, /)\n"
74 "--\n"
75 "\n"
76 "Convert this value to exact type complex.");
77 
78 #define COMPLEX___COMPLEX___METHODDEF    \
79     {"__complex__", (PyCFunction)complex___complex__, METH_NOARGS, complex___complex____doc__},
80 
81 static PyObject *
82 complex___complex___impl(PyComplexObject *self);
83 
84 static PyObject *
complex___complex__(PyComplexObject * self,PyObject * Py_UNUSED (ignored))85 complex___complex__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
86 {
87     return complex___complex___impl(self);
88 }
89 
90 PyDoc_STRVAR(complex_new__doc__,
91 "complex(real=0, imag=0)\n"
92 "--\n"
93 "\n"
94 "Create a complex number from a real part and an optional imaginary part.\n"
95 "\n"
96 "This is equivalent to (real + imag*1j) where imag defaults to 0.");
97 
98 static PyObject *
99 complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i);
100 
101 static PyObject *
complex_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)102 complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
103 {
104     PyObject *return_value = NULL;
105     static const char * const _keywords[] = {"real", "imag", NULL};
106     static _PyArg_Parser _parser = {NULL, _keywords, "complex", 0};
107     PyObject *argsbuf[2];
108     PyObject * const *fastargs;
109     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
110     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
111     PyObject *r = NULL;
112     PyObject *i = NULL;
113 
114     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
115     if (!fastargs) {
116         goto exit;
117     }
118     if (!noptargs) {
119         goto skip_optional_pos;
120     }
121     if (fastargs[0]) {
122         r = fastargs[0];
123         if (!--noptargs) {
124             goto skip_optional_pos;
125         }
126     }
127     i = fastargs[1];
128 skip_optional_pos:
129     return_value = complex_new_impl(type, r, i);
130 
131 exit:
132     return return_value;
133 }
134 /*[clinic end generated code: output=6d85094ace15677e input=a9049054013a1b77]*/
135