1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
14static PyObject *
15complex_conjugate_impl(PyComplexObject *self);
16
17static PyObject *
18complex_conjugate(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
19{
20 return complex_conjugate_impl(self);
21}
22
23PyDoc_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
31static PyObject *
32complex___getnewargs___impl(PyComplexObject *self);
33
34static PyObject *
35complex___getnewargs__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
36{
37 return complex___getnewargs___impl(self);
38}
39
40PyDoc_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
49static PyObject *
50complex___format___impl(PyComplexObject *self, PyObject *format_spec);
51
52static PyObject *
53complex___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
68exit:
69 return return_value;
70}
71
72PyDoc_STRVAR(complex_new__doc__,
73"complex(real=0, imag=0)\n"
74"--\n"
75"\n"
76"Create a complex number from a real part and an optional imaginary part.\n"
77"\n"
78"This is equivalent to (real + imag*1j) where imag defaults to 0.");
79
80static PyObject *
81complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i);
82
83static PyObject *
84complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
85{
86 PyObject *return_value = NULL;
87 static const char * const _keywords[] = {"real", "imag", NULL};
88 static _PyArg_Parser _parser = {NULL, _keywords, "complex", 0};
89 PyObject *argsbuf[2];
90 PyObject * const *fastargs;
91 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
92 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
93 PyObject *r = NULL;
94 PyObject *i = NULL;
95
96 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
97 if (!fastargs) {
98 goto exit;
99 }
100 if (!noptargs) {
101 goto skip_optional_pos;
102 }
103 if (fastargs[0]) {
104 r = fastargs[0];
105 if (!--noptargs) {
106 goto skip_optional_pos;
107 }
108 }
109 i = fastargs[1];
110skip_optional_pos:
111 return_value = complex_new_impl(type, r, i);
112
113exit:
114 return return_value;
115}
116/*[clinic end generated code: output=056cac3226d94967 input=a9049054013a1b77]*/
117