(root)/
Python-3.12.0/
Objects/
clinic/
complexobject.c.h
       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  
      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(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
      25  {
      26      return complex_conjugate_impl(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__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
      42  {
      43      return complex___getnewargs___impl(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__(PyComplexObject *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      if (PyUnicode_READY(arg) == -1) {
      69          goto exit;
      70      }
      71      format_spec = arg;
      72      return_value = complex___format___impl(self, format_spec);
      73  
      74  exit:
      75      return return_value;
      76  }
      77  
      78  PyDoc_STRVAR(complex___complex____doc__,
      79  "__complex__($self, /)\n"
      80  "--\n"
      81  "\n"
      82  "Convert this value to exact type complex.");
      83  
      84  #define COMPLEX___COMPLEX___METHODDEF    \
      85      {"__complex__", (PyCFunction)complex___complex__, METH_NOARGS, complex___complex____doc__},
      86  
      87  static PyObject *
      88  complex___complex___impl(PyComplexObject *self);
      89  
      90  static PyObject *
      91  complex___complex__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
      92  {
      93      return complex___complex___impl(self);
      94  }
      95  
      96  PyDoc_STRVAR(complex_new__doc__,
      97  "complex(real=0, imag=0)\n"
      98  "--\n"
      99  "\n"
     100  "Create a complex number from a real part and an optional imaginary part.\n"
     101  "\n"
     102  "This is equivalent to (real + imag*1j) where imag defaults to 0.");
     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          PyObject *ob_item[NUM_KEYWORDS];
     118      } _kwtuple = {
     119          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     120          .ob_item = { &_Py_ID(real), &_Py_ID(imag), },
     121      };
     122      #undef NUM_KEYWORDS
     123      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     124  
     125      #else  // !Py_BUILD_CORE
     126      #  define KWTUPLE NULL
     127      #endif  // !Py_BUILD_CORE
     128  
     129      static const char * const _keywords[] = {"real", "imag", NULL};
     130      static _PyArg_Parser _parser = {
     131          .keywords = _keywords,
     132          .fname = "complex",
     133          .kwtuple = KWTUPLE,
     134      };
     135      #undef KWTUPLE
     136      PyObject *argsbuf[2];
     137      PyObject * const *fastargs;
     138      Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     139      Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
     140      PyObject *r = NULL;
     141      PyObject *i = NULL;
     142  
     143      fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
     144      if (!fastargs) {
     145          goto exit;
     146      }
     147      if (!noptargs) {
     148          goto skip_optional_pos;
     149      }
     150      if (fastargs[0]) {
     151          r = fastargs[0];
     152          if (!--noptargs) {
     153              goto skip_optional_pos;
     154          }
     155      }
     156      i = fastargs[1];
     157  skip_optional_pos:
     158      return_value = complex_new_impl(type, r, i);
     159  
     160  exit:
     161      return return_value;
     162  }
     163  /*[clinic end generated code: output=52e85a1e258425d6 input=a9049054013a1b77]*/