| 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 |
{ |
| 26 |
return complex_conjugate_impl((PyComplexObject *)self); |
| 27 |
} |
| 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 |
{ |
| 43 |
return complex___getnewargs___impl((PyComplexObject *)self); |
| 44 |
} |
| 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 |
{ |
| 61 |
PyObject *return_value = NULL; |
| 62 |
PyObject *format_spec; |
| 63 |
|
| 64 |
if (!PyUnicode_Check(arg)) { |
| 65 |
_PyArg_BadArgument("__format__", "argument", "str", arg); |
| 66 |
goto exit; |
| 67 |
} |
| 68 |
format_spec = arg; |
| 69 |
return_value = complex___format___impl((PyComplexObject *)self, format_spec); |
| 70 |
|
| 71 |
exit: |
| 72 |
return return_value; |
| 73 |
} |
| 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 |
{ |
| 90 |
return complex___complex___impl((PyComplexObject *)self); |
| 91 |
} |
| 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 |
{ |
| 110 |
PyObject *return_value = NULL; |
| 111 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 112 |
|
| 113 |
#define NUM_KEYWORDS 2 |
| 114 |
static struct { |
| 115 |
PyGC_Head _this_is_not_used; |
| 116 |
PyObject_VAR_HEAD |
| 117 |
Py_hash_t ob_hash; |
| 118 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 119 |
} _kwtuple = { |
| 120 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 121 |
.ob_hash = -1, |
| 122 |
.ob_item = { &_Py_ID(real), &_Py_ID(imag), }, |
| 123 |
}; |
| 124 |
#undef NUM_KEYWORDS |
| 125 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 126 |
|
| 127 |
#else // !Py_BUILD_CORE |
| 128 |
# define KWTUPLE NULL |
| 129 |
#endif // !Py_BUILD_CORE |
| 130 |
|
| 131 |
static const char * const _keywords[] = {"real", "imag", NULL}; |
| 132 |
static _PyArg_Parser _parser = { |
| 133 |
.keywords = _keywords, |
| 134 |
.fname = "complex", |
| 135 |
.kwtuple = KWTUPLE, |
| 136 |
}; |
| 137 |
#undef KWTUPLE |
| 138 |
PyObject *argsbuf[2]; |
| 139 |
PyObject * const *fastargs; |
| 140 |
Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 141 |
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
| 142 |
PyObject *r = NULL; |
| 143 |
PyObject *i = NULL; |
| 144 |
|
| 145 |
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
| 146 |
/*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 147 |
if (!fastargs) { |
| 148 |
goto exit; |
| 149 |
} |
| 150 |
if (!noptargs) { |
| 151 |
goto skip_optional_pos; |
| 152 |
} |
| 153 |
if (fastargs[0]) { |
| 154 |
r = fastargs[0]; |
| 155 |
if (!--noptargs) { |
| 156 |
goto skip_optional_pos; |
| 157 |
} |
| 158 |
} |
| 159 |
i = fastargs[1]; |
| 160 |
skip_optional_pos: |
| 161 |
return_value = complex_new_impl(type, r, i); |
| 162 |
|
| 163 |
exit: |
| 164 |
return return_value; |
| 165 |
} |
| 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 |
{ |
| 182 |
PyObject *return_value = NULL; |
| 183 |
|
| 184 |
return_value = complex_from_number_impl((PyTypeObject *)type, number); |
| 185 |
|
| 186 |
return return_value; |
| 187 |
} |
| 188 |
/*[clinic end generated code: output=05d2ff43fc409733 input=a9049054013a1b77]*/ |