cpython/Objects/complexobject.c


/* Complex object implementation */

/* Borrows heavily from floatobject.c */

/* Submitted by Jim Hugunin */

#include "Python.h"
#include "pycore_call.h"          // _PyObject_CallNoArgs()
#include "pycore_complexobject.h" // _PyComplex_FormatAdvancedWriter()
#include "pycore_floatobject.h"   // _Py_convert_int_to_double()
#include "pycore_long.h"          // _PyLong_GetZero()
#include "pycore_object.h"        // _PyObject_Init()
#include "pycore_pymath.h"        // _Py_ADJUST_ERANGE2()



/*[clinic input]
class complex "PyComplexObject *" "&PyComplex_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=819e057d2d10f5ec]*/

#include "clinic/complexobject.c.h"

/* elementary operations on complex numbers */

static Py_complex c_1 =;

Py_complex
_Py_c_sum(Py_complex a, Py_complex b)
{}

Py_complex
_Py_cr_sum(Py_complex a, double b)
{}

static inline Py_complex
_Py_rc_sum(double a, Py_complex b)
{}

Py_complex
_Py_c_diff(Py_complex a, Py_complex b)
{}

Py_complex
_Py_cr_diff(Py_complex a, double b)
{}

Py_complex
_Py_rc_diff(double a, Py_complex b)
{}

Py_complex
_Py_c_neg(Py_complex a)
{}

Py_complex
_Py_c_prod(Py_complex a, Py_complex b)
{}

Py_complex
_Py_cr_prod(Py_complex a, double b)
{}

static inline Py_complex
_Py_rc_prod(double a, Py_complex b)
{}

/* Avoid bad optimization on Windows ARM64 until the compiler is fixed */
#ifdef _M_ARM64
#pragma optimize("", off)
#endif
Py_complex
_Py_c_quot(Py_complex a, Py_complex b)
{}

Py_complex
_Py_cr_quot(Py_complex a, double b)
{}

/* an equivalent of _Py_c_quot() function, when 1st argument is real */
Py_complex
_Py_rc_quot(double a, Py_complex b)
{}
#ifdef _M_ARM64
#pragma optimize("", on)
#endif

Py_complex
_Py_c_pow(Py_complex a, Py_complex b)
{}

static Py_complex
c_powu(Py_complex x, long n)
{}

static Py_complex
c_powi(Py_complex x, long n)
{}

double
_Py_c_abs(Py_complex z)
{}

static PyObject *
complex_subtype_from_c_complex(PyTypeObject *type, Py_complex cval)
{}

PyObject *
PyComplex_FromCComplex(Py_complex cval)
{}

static PyObject *
complex_subtype_from_doubles(PyTypeObject *type, double real, double imag)
{}

PyObject *
PyComplex_FromDoubles(double real, double imag)
{}

static PyObject * try_complex_special_method(PyObject *);

double
PyComplex_RealAsDouble(PyObject *op)
{}

double
PyComplex_ImagAsDouble(PyObject *op)
{}

static PyObject *
try_complex_special_method(PyObject *op)
{}

Py_complex
PyComplex_AsCComplex(PyObject *op)
{}

static PyObject *
complex_repr(PyComplexObject *v)
{}

static Py_hash_t
complex_hash(PyComplexObject *v)
{}

/* This macro may return! */
#define TO_COMPLEX(obj, c)

static int
real_to_double(PyObject **pobj, double *dbl)
{}

static int
real_to_complex(PyObject **pobj, Py_complex *pc)
{}

/* Complex arithmetic rules implement special mixed-mode case where combining
   a pure-real (float or int) value and a complex value is performed directly
   without first coercing the real value to a complex value.

   Let us consider the addition as an example, assuming that ints are implicitly
   converted to floats.  We have the following rules (up to variants with changed
   order of operands):

       complex(a, b) + complex(c, d) = complex(a + c, b + d)
       float(a) + complex(b, c) = complex(a + b, c)

   Similar rules are implemented for subtraction, multiplication and division.
   See C11's Annex G, sections G.5.1 and G.5.2.
 */

#define COMPLEX_BINOP(NAME, FUNC)

COMPLEX_BINOP()
COMPLEX_BINOP()
COMPLEX_BINOP()
COMPLEX_BINOP()

static PyObject *
complex_pow(PyObject *v, PyObject *w, PyObject *z)
{}

static PyObject *
complex_neg(PyComplexObject *v)
{}

static PyObject *
complex_pos(PyComplexObject *v)
{}

static PyObject *
complex_abs(PyComplexObject *v)
{}

static int
complex_bool(PyComplexObject *v)
{}

static PyObject *
complex_richcompare(PyObject *v, PyObject *w, int op)
{}

/*[clinic input]
complex.conjugate

Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.
[clinic start generated code]*/

static PyObject *
complex_conjugate_impl(PyComplexObject *self)
/*[clinic end generated code: output=5059ef162edfc68e input=5fea33e9747ec2c4]*/
{}

/*[clinic input]
complex.__getnewargs__

[clinic start generated code]*/

static PyObject *
complex___getnewargs___impl(PyComplexObject *self)
/*[clinic end generated code: output=689b8206e8728934 input=539543e0a50533d7]*/
{}


/*[clinic input]
complex.__format__

    format_spec: unicode
    /

Convert to a string according to format_spec.
[clinic start generated code]*/

static PyObject *
complex___format___impl(PyComplexObject *self, PyObject *format_spec)
/*[clinic end generated code: output=bfcb60df24cafea0 input=014ef5488acbe1d5]*/
{}

/*[clinic input]
complex.__complex__

Convert this value to exact type complex.
[clinic start generated code]*/

static PyObject *
complex___complex___impl(PyComplexObject *self)
/*[clinic end generated code: output=e6b35ba3d275dc9c input=3589ada9d27db854]*/
{}


static PyObject *
complex_from_string_inner(const char *s, Py_ssize_t len, void *type)
{}

static PyObject *
complex_subtype_from_string(PyTypeObject *type, PyObject *v)
{}

/* The constructor should only accept a string as a positional argument,
 * not as by the 'real' keyword.  But Argument Clinic does not allow
 * to distinguish between argument passed positionally and by keyword.
 * So the constructor must be split into two parts: actual_complex_new()
 * handles the case of no arguments and one positional argument, and calls
 * complex_new(), implemented with Argument Clinic, to handle the remaining
 * cases: 'real' and 'imag' arguments.  This separation is well suited
 * for different constructor roles: converting a string or number to a complex
 * number and constructing a complex number from real and imaginary parts.
 */
static PyObject *
actual_complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{}

/*[clinic input]
@classmethod
complex.__new__ as complex_new
    real as r: object(c_default="NULL") = 0
    imag as i: object(c_default="NULL") = 0

Create a complex number from a string or numbers.

If a string is given, parse it as a complex number.
If a single number is given, convert it to a complex number.
If the 'real' or 'imag' arguments are given, create a complex number
with the specified real and imaginary components.
[clinic start generated code]*/

static PyObject *
complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
/*[clinic end generated code: output=b6c7dd577b537dc1 input=ff4268dc540958a4]*/
{}

/*[clinic input]
@classmethod
complex.from_number

    number: object
    /

Convert number to a complex floating-point number.
[clinic start generated code]*/

static PyObject *
complex_from_number(PyTypeObject *type, PyObject *number)
/*[clinic end generated code: output=658a7a5fb0de074d input=3f8bdd3a2bc3facd]*/
{}

static PyMethodDef complex_methods[] =;

static PyMemberDef complex_members[] =;

static PyNumberMethods complex_as_number =;

PyTypeObject PyComplex_Type =;