@@ -1394,6 +1394,7 @@ imaginary_new_impl(PyTypeObject *type, PyObject *x)
13941394 }
13951395
13961396 PyNumberMethods * nbx = Py_TYPE (x )-> tp_as_number ;
1397+
13971398 if (nbx == NULL || (nbx -> nb_float == NULL && nbx -> nb_index == NULL
13981399 && !PyFloat_Check (x )))
13991400 {
@@ -1404,17 +1405,17 @@ imaginary_new_impl(PyTypeObject *type, PyObject *x)
14041405 }
14051406
14061407 PyObject * tmp = PyNumber_Float (x );
1408+
14071409 if (tmp == NULL ) {
14081410 return NULL ;
14091411 }
14101412
14111413 PyObject * ret = type -> tp_alloc (type , 0 );
1414+
14121415 if (ret != NULL ) {
14131416 ((PyComplexObject * )ret )-> cval = (Py_complex ) {0.0 , PyFloat_AS_DOUBLE (tmp )};
14141417 }
1415-
14161418 Py_DECREF (tmp );
1417-
14181419 return ret ;
14191420}
14201421
@@ -1423,6 +1424,7 @@ PyImaginary_FromDouble(double imag)
14231424{
14241425 /* Inline PyObject_New */
14251426 PyComplexObject * op = PyObject_Malloc (sizeof (PyComplexObject ));
1427+
14261428 if (op == NULL ) {
14271429 return PyErr_NoMemory ();
14281430 }
@@ -1454,6 +1456,7 @@ imaginary_add(PyObject *v, PyObject *w)
14541456{
14551457 if (!PyImaginary_Check (v )) {
14561458 PyObject * tmp = v ;
1459+
14571460 v = w ;
14581461 w = tmp ;
14591462 }
@@ -1468,7 +1471,6 @@ imaginary_add(PyObject *v, PyObject *w)
14681471 else if (real_to_double (& w , & b ) < 0 ) {
14691472 return w ;
14701473 }
1471-
14721474 return PyComplex_FromDoubles (b , a );
14731475}
14741476
@@ -1503,7 +1505,6 @@ imaginary_sub(PyObject *v, PyObject *w)
15031505 else if (real_to_double (& w , & b ) < 0 ) {
15041506 return w ;
15051507 }
1506-
15071508 return PyComplex_FromDoubles (- b , a );
15081509}
15091510
@@ -1512,6 +1513,7 @@ imaginary_mul(PyObject *v, PyObject *w)
15121513{
15131514 if (!PyImaginary_Check (v )) {
15141515 PyObject * tmp = v ;
1516+
15151517 v = w ;
15161518 w = tmp ;
15171519 }
@@ -1530,7 +1532,6 @@ imaginary_mul(PyObject *v, PyObject *w)
15301532 else if (real_to_double (& w , & b ) < 0 ) {
15311533 return w ;
15321534 }
1533-
15341535 return PyImaginary_FromDouble (a * b );
15351536}
15361537
@@ -1544,10 +1545,12 @@ imaginary_div(PyObject *v, PyObject *w)
15441545 if (b ) {
15451546 if (PyImaginary_Check (v )) {
15461547 double a = ((PyComplexObject * )(v ))-> cval .imag ;
1548+
15471549 return PyFloat_FromDouble (a /b );
15481550 }
15491551 if (PyComplex_Check (v )) {
15501552 Py_complex a = ((PyComplexObject * )(v ))-> cval ;
1553+
15511554 return PyComplex_FromDoubles (a .imag /b , - a .real /b );
15521555 }
15531556 if (real_to_double (& v , & a ) < 0 ) {
@@ -1562,6 +1565,7 @@ imaginary_div(PyObject *v, PyObject *w)
15621565
15631566 if (PyComplex_Check (w )) {
15641567 Py_complex b = ((PyComplexObject * )(w ))-> cval ;
1568+
15651569 errno = 0 ;
15661570 b = _Py_rc_quot (a , b );
15671571 b = (Py_complex ){- b .imag , b .real };
@@ -1576,7 +1580,6 @@ imaginary_div(PyObject *v, PyObject *w)
15761580 return PyImaginary_FromDouble (a /b );
15771581 }
15781582 }
1579-
15801583 PyErr_SetString (PyExc_ZeroDivisionError , "complex division by zero" );
15811584 return NULL ;
15821585}
@@ -1592,6 +1595,7 @@ imaginary_conjugate_impl(PyComplexObject *self)
15921595/*[clinic end generated code: output=247bb3742efd769d input=8dcd1c93a873c492]*/
15931596{
15941597 Py_complex c = self -> cval ;
1598+
15951599 c .imag = - c .imag ;
15961600 return PyImaginary_FromDouble (c .imag );
15971601}
@@ -1606,6 +1610,7 @@ imaginary___getnewargs___impl(PyComplexObject *self)
16061610/*[clinic end generated code: output=a587156eda821f7d input=da4b7e53915987d5]*/
16071611{
16081612 Py_complex c = self -> cval ;
1613+
16091614 return Py_BuildValue ("(d)" , c .imag );
16101615}
16111616
0 commit comments