2 /* Complex object implementation */
4 /* Borrows heavily from floatobject.c */
6 /* Submitted by Jim Hugunin */
9 #include "structmember.h"
15 #ifndef WITHOUT_COMPLEX
17 /* elementary operations on complex numbers */
19 static Py_complex c_1
= {1., 0.};
22 c_sum(Py_complex a
, Py_complex b
)
25 r
.real
= a
.real
+ b
.real
;
26 r
.imag
= a
.imag
+ b
.imag
;
31 c_diff(Py_complex a
, Py_complex b
)
34 r
.real
= a
.real
- b
.real
;
35 r
.imag
= a
.imag
- b
.imag
;
49 c_prod(Py_complex a
, Py_complex b
)
52 r
.real
= a
.real
*b
.real
- a
.imag
*b
.imag
;
53 r
.imag
= a
.real
*b
.imag
+ a
.imag
*b
.real
;
58 c_quot(Py_complex a
, Py_complex b
)
60 /******************************************************************
61 This was the original algorithm. It's grossly prone to spurious
62 overflow and underflow errors. It also merrily divides by 0 despite
63 checking for that(!). The code still serves a doc purpose here, as
64 the algorithm following is a simple by-cases transformation of this
68 double d = b.real*b.real + b.imag*b.imag;
71 r.real = (a.real*b.real + a.imag*b.imag)/d;
72 r.imag = (a.imag*b.real - a.real*b.imag)/d;
74 ******************************************************************/
76 /* This algorithm is better, and is pretty obvious: first divide the
77 * numerators and denominator by whichever of {b.real, b.imag} has
78 * larger magnitude. The earliest reference I found was to CACM
79 * Algorithm 116 (Complex Division, Robert L. Smith, Stanford
80 * University). As usual, though, we're still ignoring all IEEE
83 Py_complex r
; /* the result */
84 const double abs_breal
= b
.real
< 0 ? -b
.real
: b
.real
;
85 const double abs_bimag
= b
.imag
< 0 ? -b
.imag
: b
.imag
;
87 if (abs_breal
>= abs_bimag
) {
88 /* divide tops and bottom by b.real */
89 if (abs_breal
== 0.0) {
91 r
.real
= r
.imag
= 0.0;
94 const double ratio
= b
.imag
/ b
.real
;
95 const double denom
= b
.real
+ b
.imag
* ratio
;
96 r
.real
= (a
.real
+ a
.imag
* ratio
) / denom
;
97 r
.imag
= (a
.imag
- a
.real
* ratio
) / denom
;
101 /* divide tops and bottom by b.imag */
102 const double ratio
= b
.real
/ b
.imag
;
103 const double denom
= b
.real
* ratio
+ b
.imag
;
104 assert(b
.imag
!= 0.0);
105 r
.real
= (a
.real
* ratio
+ a
.imag
) / denom
;
106 r
.imag
= (a
.imag
* ratio
- a
.real
) / denom
;
112 c_pow(Py_complex a
, Py_complex b
)
115 double vabs
,len
,at
,phase
;
116 if (b
.real
== 0. && b
.imag
== 0.) {
120 else if (a
.real
== 0. && a
.imag
== 0.) {
121 if (b
.imag
!= 0. || b
.real
< 0.)
127 vabs
= hypot(a
.real
,a
.imag
);
128 len
= pow(vabs
,b
.real
);
129 at
= atan2(a
.imag
, a
.real
);
132 len
/= exp(at
*b
.imag
);
133 phase
+= b
.imag
*log(vabs
);
135 r
.real
= len
*cos(phase
);
136 r
.imag
= len
*sin(phase
);
142 c_powu(Py_complex x
, long n
)
148 while (mask
> 0 && n
>= mask
) {
158 c_powi(Py_complex x
, long n
)
162 if (n
> 100 || n
< -100) {
163 cn
.real
= (double) n
;
170 return c_quot(c_1
,c_powu(x
,-n
));
177 /* sets errno = ERANGE on overflow; otherwise errno = 0 */
180 if (!Py_IS_FINITE(z
.real
) || !Py_IS_FINITE(z
.imag
)) {
181 /* C99 rules: if either the real or the imaginary part is an
182 infinity, return infinity, even if the other part is a
184 if (Py_IS_INFINITY(z
.real
)) {
185 result
= fabs(z
.real
);
189 if (Py_IS_INFINITY(z
.imag
)) {
190 result
= fabs(z
.imag
);
194 /* either the real or imaginary part is a NaN,
195 and neither is infinite. Result should be NaN. */
198 result
= hypot(z
.real
, z
.imag
);
199 if (!Py_IS_FINITE(result
))
207 complex_subtype_from_c_complex(PyTypeObject
*type
, Py_complex cval
)
211 op
= type
->tp_alloc(type
, 0);
213 ((PyComplexObject
*)op
)->cval
= cval
;
218 PyComplex_FromCComplex(Py_complex cval
)
220 register PyComplexObject
*op
;
222 /* Inline PyObject_New */
223 op
= (PyComplexObject
*) PyObject_MALLOC(sizeof(PyComplexObject
));
225 return PyErr_NoMemory();
226 PyObject_INIT(op
, &PyComplex_Type
);
228 return (PyObject
*) op
;
232 complex_subtype_from_doubles(PyTypeObject
*type
, double real
, double imag
)
237 return complex_subtype_from_c_complex(type
, c
);
241 PyComplex_FromDoubles(double real
, double imag
)
246 return PyComplex_FromCComplex(c
);
250 PyComplex_RealAsDouble(PyObject
*op
)
252 if (PyComplex_Check(op
)) {
253 return ((PyComplexObject
*)op
)->cval
.real
;
256 return PyFloat_AsDouble(op
);
261 PyComplex_ImagAsDouble(PyObject
*op
)
263 if (PyComplex_Check(op
)) {
264 return ((PyComplexObject
*)op
)->cval
.imag
;
272 PyComplex_AsCComplex(PyObject
*op
)
275 PyObject
*newop
= NULL
;
276 static PyObject
*complex_str
= NULL
;
279 /* If op is already of type PyComplex_Type, return its value */
280 if (PyComplex_Check(op
)) {
281 return ((PyComplexObject
*)op
)->cval
;
283 /* If not, use op's __complex__ method, if it exists */
285 /* return -1 on failure */
289 if (complex_str
== NULL
) {
290 if (!(complex_str
= PyUnicode_FromString("__complex__")))
295 PyObject
*complexfunc
;
296 complexfunc
= _PyType_Lookup(op
->ob_type
, complex_str
);
297 /* complexfunc is a borrowed reference */
299 newop
= PyObject_CallFunctionObjArgs(complexfunc
, op
, NULL
);
306 if (!PyComplex_Check(newop
)) {
307 PyErr_SetString(PyExc_TypeError
,
308 "__complex__ should return a complex object");
312 cv
= ((PyComplexObject
*)newop
)->cval
;
316 /* If neither of the above works, interpret op as a float giving the
317 real part of the result, and fill in the imaginary part as 0. */
319 /* PyFloat_AsDouble will return -1 on failure */
320 cv
.real
= PyFloat_AsDouble(op
);
326 complex_dealloc(PyObject
*op
)
328 op
->ob_type
->tp_free(op
);
333 complex_format(PyComplexObject
*v
, int precision
, char format_code
)
335 PyObject
*result
= NULL
;
338 /* If these are non-NULL, they'll need to be freed. */
343 /* These do not need to be freed. re is either an alias
344 for pre or a pointer to a constant. lead and tail
345 are pointers to constants. */
350 if (v
->cval
.real
== 0. && copysign(1.0, v
->cval
.real
)==1.0) {
352 im
= PyOS_double_to_string(v
->cval
.imag
, format_code
,
359 /* Format imaginary part with sign, real part without */
360 pre
= PyOS_double_to_string(v
->cval
.real
, format_code
,
368 im
= PyOS_double_to_string(v
->cval
.imag
, format_code
,
369 precision
, Py_DTSF_SIGN
, NULL
);
377 /* Alloc the final buffer. Add one for the "j" in the format string,
378 and one for the trailing zero. */
379 len
= strlen(lead
) + strlen(re
) + strlen(im
) + strlen(tail
) + 2;
380 buf
= PyMem_Malloc(len
);
385 PyOS_snprintf(buf
, len
, "%s%s%sj%s", lead
, re
, im
, tail
);
386 result
= PyUnicode_FromString(buf
);
396 complex_repr(PyComplexObject
*v
)
398 return complex_format(v
, 0, 'r');
402 complex_str(PyComplexObject
*v
)
404 return complex_format(v
, PyFloat_STR_PRECISION
, 'g');
408 complex_hash(PyComplexObject
*v
)
410 long hashreal
, hashimag
, combined
;
411 hashreal
= _Py_HashDouble(v
->cval
.real
);
414 hashimag
= _Py_HashDouble(v
->cval
.imag
);
417 /* Note: if the imaginary part is 0, hashimag is 0 now,
418 * so the following returns hashreal unchanged. This is
419 * important because numbers of different types that
420 * compare equal must have the same hash value, so that
421 * hash(x + 0*j) must equal hash(x).
423 combined
= hashreal
+ 1000003 * hashimag
;
429 /* This macro may return! */
430 #define TO_COMPLEX(obj, c) \
431 if (PyComplex_Check(obj)) \
432 c = ((PyComplexObject *)(obj))->cval; \
433 else if (to_complex(&(obj), &(c)) < 0) \
437 to_complex(PyObject
**pobj
, Py_complex
*pc
)
439 PyObject
*obj
= *pobj
;
441 pc
->real
= pc
->imag
= 0.0;
442 if (PyLong_Check(obj
)) {
443 pc
->real
= PyLong_AsDouble(obj
);
444 if (pc
->real
== -1.0 && PyErr_Occurred()) {
450 if (PyFloat_Check(obj
)) {
451 pc
->real
= PyFloat_AsDouble(obj
);
454 Py_INCREF(Py_NotImplemented
);
455 *pobj
= Py_NotImplemented
;
461 complex_add(PyObject
*v
, PyObject
*w
)
467 PyFPE_START_PROTECT("complex_add", return 0)
468 result
= c_sum(a
, b
);
469 PyFPE_END_PROTECT(result
)
470 return PyComplex_FromCComplex(result
);
474 complex_sub(PyObject
*v
, PyObject
*w
)
480 PyFPE_START_PROTECT("complex_sub", return 0)
481 result
= c_diff(a
, b
);
482 PyFPE_END_PROTECT(result
)
483 return PyComplex_FromCComplex(result
);
487 complex_mul(PyObject
*v
, PyObject
*w
)
493 PyFPE_START_PROTECT("complex_mul", return 0)
494 result
= c_prod(a
, b
);
495 PyFPE_END_PROTECT(result
)
496 return PyComplex_FromCComplex(result
);
500 complex_div(PyObject
*v
, PyObject
*w
)
506 PyFPE_START_PROTECT("complex_div", return 0)
509 PyFPE_END_PROTECT(quot
)
511 PyErr_SetString(PyExc_ZeroDivisionError
, "complex division");
514 return PyComplex_FromCComplex(quot
);
518 complex_remainder(PyObject
*v
, PyObject
*w
)
520 PyErr_SetString(PyExc_TypeError
,
521 "can't mod complex numbers.");
527 complex_divmod(PyObject
*v
, PyObject
*w
)
529 PyErr_SetString(PyExc_TypeError
,
530 "can't take floor or mod of complex number.");
535 complex_pow(PyObject
*v
, PyObject
*w
, PyObject
*z
)
545 PyErr_SetString(PyExc_ValueError
, "complex modulo");
548 PyFPE_START_PROTECT("complex_pow", return 0)
551 int_exponent
= (long)exponent
.real
;
552 if (exponent
.imag
== 0. && exponent
.real
== int_exponent
)
553 p
= c_powi(a
, int_exponent
);
555 p
= c_pow(a
, exponent
);
558 Py_ADJUST_ERANGE2(p
.real
, p
.imag
);
560 PyErr_SetString(PyExc_ZeroDivisionError
,
561 "0.0 to a negative or complex power");
564 else if (errno
== ERANGE
) {
565 PyErr_SetString(PyExc_OverflowError
,
566 "complex exponentiation");
569 return PyComplex_FromCComplex(p
);
573 complex_int_div(PyObject
*v
, PyObject
*w
)
575 PyErr_SetString(PyExc_TypeError
,
576 "can't take floor of complex number.");
581 complex_neg(PyComplexObject
*v
)
584 neg
.real
= -v
->cval
.real
;
585 neg
.imag
= -v
->cval
.imag
;
586 return PyComplex_FromCComplex(neg
);
590 complex_pos(PyComplexObject
*v
)
592 if (PyComplex_CheckExact(v
)) {
594 return (PyObject
*)v
;
597 return PyComplex_FromCComplex(v
->cval
);
601 complex_abs(PyComplexObject
*v
)
605 PyFPE_START_PROTECT("complex_abs", return 0)
606 result
= c_abs(v
->cval
);
607 PyFPE_END_PROTECT(result
)
609 if (errno
== ERANGE
) {
610 PyErr_SetString(PyExc_OverflowError
,
611 "absolute value too large");
614 return PyFloat_FromDouble(result
);
618 complex_bool(PyComplexObject
*v
)
620 return v
->cval
.real
!= 0.0 || v
->cval
.imag
!= 0.0;
624 complex_richcompare(PyObject
*v
, PyObject
*w
, int op
)
631 if (op
!= Py_EQ
&& op
!= Py_NE
) {
632 /* XXX Should eventually return NotImplemented */
633 PyErr_SetString(PyExc_TypeError
,
634 "no ordering relation is defined for complex numbers");
638 if ((i
.real
== j
.real
&& i
.imag
== j
.imag
) == (op
== Py_EQ
))
648 complex_int(PyObject
*v
)
650 PyErr_SetString(PyExc_TypeError
,
651 "can't convert complex to int; use int(abs(z))");
656 complex_float(PyObject
*v
)
658 PyErr_SetString(PyExc_TypeError
,
659 "can't convert complex to float; use abs(z)");
664 complex_conjugate(PyObject
*self
)
667 c
= ((PyComplexObject
*)self
)->cval
;
669 return PyComplex_FromCComplex(c
);
672 PyDoc_STRVAR(complex_conjugate_doc
,
673 "complex.conjugate() -> complex\n"
675 "Returns the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.");
678 complex_getnewargs(PyComplexObject
*v
)
680 Py_complex c
= v
->cval
;
681 return Py_BuildValue("(dd)", c
.real
, c
.imag
);
684 PyDoc_STRVAR(complex__format__doc
,
685 "complex.__format__() -> str\n"
687 "Converts to a string according to format_spec.");
690 complex__format__(PyObject
* self
, PyObject
* args
)
692 PyObject
*format_spec
;
694 if (!PyArg_ParseTuple(args
, "U:__format__", &format_spec
))
696 return _PyComplex_FormatAdvanced(self
,
697 PyUnicode_AS_UNICODE(format_spec
),
698 PyUnicode_GET_SIZE(format_spec
));
703 complex_is_finite(PyObject
*self
)
706 c
= ((PyComplexObject
*)self
)->cval
;
707 return PyBool_FromLong((long)(Py_IS_FINITE(c
.real
) &&
708 Py_IS_FINITE(c
.imag
)));
711 PyDoc_STRVAR(complex_is_finite_doc
,
712 "complex.is_finite() -> bool\n"
714 "Returns True if the real and the imaginary part is finite.");
717 static PyMethodDef complex_methods
[] = {
718 {"conjugate", (PyCFunction
)complex_conjugate
, METH_NOARGS
,
719 complex_conjugate_doc
},
721 {"is_finite", (PyCFunction
)complex_is_finite
, METH_NOARGS
,
722 complex_is_finite_doc
},
724 {"__getnewargs__", (PyCFunction
)complex_getnewargs
, METH_NOARGS
},
725 {"__format__", (PyCFunction
)complex__format__
,
726 METH_VARARGS
, complex__format__doc
},
727 {NULL
, NULL
} /* sentinel */
730 static PyMemberDef complex_members
[] = {
731 {"real", T_DOUBLE
, offsetof(PyComplexObject
, cval
.real
), READONLY
,
732 "the real part of a complex number"},
733 {"imag", T_DOUBLE
, offsetof(PyComplexObject
, cval
.imag
), READONLY
,
734 "the imaginary part of a complex number"},
739 complex_subtype_from_string(PyTypeObject
*type
, PyObject
*v
)
741 const char *s
, *start
;
743 double x
=0.0, y
=0.0, z
;
748 if (PyUnicode_Check(v
)) {
749 if (PyUnicode_GET_SIZE(v
) >= (Py_ssize_t
)sizeof(s_buffer
)) {
750 PyErr_SetString(PyExc_ValueError
,
751 "complex() literal too large to convert");
754 if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v
),
755 PyUnicode_GET_SIZE(v
),
762 else if (PyObject_AsCharBuffer(v
, &s
, &len
)) {
763 PyErr_SetString(PyExc_TypeError
,
764 "complex() arg is not a string");
768 /* position on first nonblank */
770 while (Py_ISSPACE(*s
))
773 /* Skip over possible bracket from repr(). */
776 while (Py_ISSPACE(*s
))
780 /* a valid complex string usually takes one of the three forms:
782 <float> - real part only
783 <float>j - imaginary part only
784 <float><signed-float>j - real and imaginary parts
786 where <float> represents any numeric string that's accepted by the
787 float constructor (including 'nan', 'inf', 'infinity', etc.), and
788 <signed-float> is any string of the form <float> whose first
789 character is '+' or '-'.
791 For backwards compatibility, the extra forms
797 are also accepted, though support for these forms may be removed from
798 a future version of Python.
801 /* first look for forms starting with <float> */
802 z
= PyOS_string_to_double(s
, &end
, PyExc_OverflowError
);
803 if (z
== -1.0 && PyErr_Occurred()) {
804 if (PyErr_ExceptionMatches(PyExc_ValueError
))
810 /* all 4 forms starting with <float> land here */
812 if (*s
== '+' || *s
== '-') {
813 /* <float><signed-float>j | <float><sign>j */
815 y
= PyOS_string_to_double(s
, &end
, PyExc_OverflowError
);
816 if (y
== -1.0 && PyErr_Occurred()) {
817 if (PyErr_ExceptionMatches(PyExc_ValueError
))
823 /* <float><signed-float>j */
827 y
= *s
== '+' ? 1.0 : -1.0;
830 if (!(*s
== 'j' || *s
== 'J'))
834 else if (*s
== 'j' || *s
== 'J') {
844 /* not starting with <float>; must be <sign>j or j */
845 if (*s
== '+' || *s
== '-') {
847 y
= *s
== '+' ? 1.0 : -1.0;
853 if (!(*s
== 'j' || *s
== 'J'))
858 /* trailing whitespace and closing bracket */
859 while (Py_ISSPACE(*s
))
862 /* if there was an opening parenthesis, then the corresponding
863 closing parenthesis should be right here */
867 while (Py_ISSPACE(*s
))
871 /* we should now be at the end of the string */
875 return complex_subtype_from_doubles(type
, x
, y
);
878 PyErr_SetString(PyExc_ValueError
,
879 "complex() arg is a malformed string");
884 complex_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
886 PyObject
*r
, *i
, *tmp
, *f
;
887 PyNumberMethods
*nbr
, *nbi
= NULL
;
890 int cr_is_complex
= 0;
891 int ci_is_complex
= 0;
892 static PyObject
*complexstr
;
893 static char *kwlist
[] = {"real", "imag", 0};
897 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "|OO:complex", kwlist
,
901 /* Special-case for a single argument when type(arg) is complex. */
902 if (PyComplex_CheckExact(r
) && i
== NULL
&&
903 type
== &PyComplex_Type
) {
904 /* Note that we can't know whether it's safe to return
905 a complex *subclass* instance as-is, hence the restriction
906 to exact complexes here. If either the input or the
907 output is a complex subclass, it will be handled below
908 as a non-orthogonal vector. */
912 if (PyUnicode_Check(r
)) {
914 PyErr_SetString(PyExc_TypeError
,
915 "complex() can't take second arg"
916 " if first is a string");
919 return complex_subtype_from_string(type
, r
);
921 if (i
!= NULL
&& PyUnicode_Check(i
)) {
922 PyErr_SetString(PyExc_TypeError
,
923 "complex() second arg can't be a string");
927 /* XXX Hack to support classes with __complex__ method */
928 if (complexstr
== NULL
) {
929 complexstr
= PyUnicode_InternFromString("__complex__");
930 if (complexstr
== NULL
)
933 f
= PyObject_GetAttr(r
, complexstr
);
937 PyObject
*args
= PyTuple_New(0);
940 r
= PyEval_CallObject(f
, args
);
947 nbr
= r
->ob_type
->tp_as_number
;
949 nbi
= i
->ob_type
->tp_as_number
;
950 if (nbr
== NULL
|| nbr
->nb_float
== NULL
||
951 ((i
!= NULL
) && (nbi
== NULL
|| nbi
->nb_float
== NULL
))) {
952 PyErr_SetString(PyExc_TypeError
,
953 "complex() argument must be a string or a number");
960 /* If we get this far, then the "real" and "imag" parts should
961 both be treated as numbers, and the constructor should return a
962 complex number equal to (real + imag*1j).
964 Note that we do NOT assume the input to already be in canonical
965 form; the "real" and "imag" parts might themselves be complex
966 numbers, which slightly complicates the code below. */
967 if (PyComplex_Check(r
)) {
968 /* Note that if r is of a complex subtype, we're only
969 retaining its real & imag parts here, and the return
970 value is (properly) of the builtin complex type. */
971 cr
= ((PyComplexObject
*)r
)->cval
;
978 /* The "real" part really is entirely real, and contributes
979 nothing in the imaginary direction.
980 Just treat it as a double. */
981 tmp
= PyNumber_Float(r
);
983 /* r was a newly created complex number, rather
984 than the original "real" argument. */
989 if (!PyFloat_Check(tmp
)) {
990 PyErr_SetString(PyExc_TypeError
,
991 "float(r) didn't return a float");
995 cr
.real
= PyFloat_AsDouble(tmp
);
996 cr
.imag
= 0.0; /* Shut up compiler warning */
1002 else if (PyComplex_Check(i
)) {
1003 ci
= ((PyComplexObject
*)i
)->cval
;
1006 /* The "imag" part really is entirely imaginary, and
1007 contributes nothing in the real direction.
1008 Just treat it as a double. */
1009 tmp
= (*nbi
->nb_float
)(i
);
1012 ci
.real
= PyFloat_AsDouble(tmp
);
1015 /* If the input was in canonical form, then the "real" and "imag"
1016 parts are real numbers, so that ci.imag and cr.imag are zero.
1017 We need this correction in case they were not real numbers. */
1019 if (ci_is_complex
) {
1022 if (cr_is_complex
) {
1025 return complex_subtype_from_doubles(type
, cr
.real
, ci
.real
);
1028 PyDoc_STRVAR(complex_doc
,
1029 "complex(real[, imag]) -> complex number\n"
1031 "Create a complex number from a real part and an optional imaginary part.\n"
1032 "This is equivalent to (real + imag*1j) where imag defaults to 0.");
1034 static PyNumberMethods complex_as_number
= {
1035 (binaryfunc
)complex_add
, /* nb_add */
1036 (binaryfunc
)complex_sub
, /* nb_subtract */
1037 (binaryfunc
)complex_mul
, /* nb_multiply */
1038 (binaryfunc
)complex_remainder
, /* nb_remainder */
1039 (binaryfunc
)complex_divmod
, /* nb_divmod */
1040 (ternaryfunc
)complex_pow
, /* nb_power */
1041 (unaryfunc
)complex_neg
, /* nb_negative */
1042 (unaryfunc
)complex_pos
, /* nb_positive */
1043 (unaryfunc
)complex_abs
, /* nb_absolute */
1044 (inquiry
)complex_bool
, /* nb_bool */
1051 complex_int
, /* nb_int */
1052 0, /* nb_reserved */
1053 complex_float
, /* nb_float */
1054 0, /* nb_inplace_add */
1055 0, /* nb_inplace_subtract */
1056 0, /* nb_inplace_multiply*/
1057 0, /* nb_inplace_remainder */
1058 0, /* nb_inplace_power */
1059 0, /* nb_inplace_lshift */
1060 0, /* nb_inplace_rshift */
1061 0, /* nb_inplace_and */
1062 0, /* nb_inplace_xor */
1063 0, /* nb_inplace_or */
1064 (binaryfunc
)complex_int_div
, /* nb_floor_divide */
1065 (binaryfunc
)complex_div
, /* nb_true_divide */
1066 0, /* nb_inplace_floor_divide */
1067 0, /* nb_inplace_true_divide */
1070 PyTypeObject PyComplex_Type
= {
1071 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
1073 sizeof(PyComplexObject
),
1075 complex_dealloc
, /* tp_dealloc */
1079 0, /* tp_reserved */
1080 (reprfunc
)complex_repr
, /* tp_repr */
1081 &complex_as_number
, /* tp_as_number */
1082 0, /* tp_as_sequence */
1083 0, /* tp_as_mapping */
1084 (hashfunc
)complex_hash
, /* tp_hash */
1086 (reprfunc
)complex_str
, /* tp_str */
1087 PyObject_GenericGetAttr
, /* tp_getattro */
1088 0, /* tp_setattro */
1089 0, /* tp_as_buffer */
1090 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /* tp_flags */
1091 complex_doc
, /* tp_doc */
1092 0, /* tp_traverse */
1094 complex_richcompare
, /* tp_richcompare */
1095 0, /* tp_weaklistoffset */
1097 0, /* tp_iternext */
1098 complex_methods
, /* tp_methods */
1099 complex_members
, /* tp_members */
1103 0, /* tp_descr_get */
1104 0, /* tp_descr_set */
1105 0, /* tp_dictoffset */
1107 PyType_GenericAlloc
, /* tp_alloc */
1108 complex_new
, /* tp_new */
1109 PyObject_Del
, /* tp_free */