@@ -1394,6 +1394,7 @@ imaginary_new_impl(PyTypeObject *type, PyObject *x)
1394
1394
}
1395
1395
1396
1396
PyNumberMethods * nbx = Py_TYPE (x )-> tp_as_number ;
1397
+
1397
1398
if (nbx == NULL || (nbx -> nb_float == NULL && nbx -> nb_index == NULL
1398
1399
&& !PyFloat_Check (x )))
1399
1400
{
@@ -1404,17 +1405,17 @@ imaginary_new_impl(PyTypeObject *type, PyObject *x)
1404
1405
}
1405
1406
1406
1407
PyObject * tmp = PyNumber_Float (x );
1408
+
1407
1409
if (tmp == NULL ) {
1408
1410
return NULL ;
1409
1411
}
1410
1412
1411
1413
PyObject * ret = type -> tp_alloc (type , 0 );
1414
+
1412
1415
if (ret != NULL ) {
1413
1416
((PyComplexObject * )ret )-> cval = (Py_complex ) {0.0 , PyFloat_AS_DOUBLE (tmp )};
1414
1417
}
1415
-
1416
1418
Py_DECREF (tmp );
1417
-
1418
1419
return ret ;
1419
1420
}
1420
1421
@@ -1423,6 +1424,7 @@ PyImaginary_FromDouble(double imag)
1423
1424
{
1424
1425
/* Inline PyObject_New */
1425
1426
PyComplexObject * op = PyObject_Malloc (sizeof (PyComplexObject ));
1427
+
1426
1428
if (op == NULL ) {
1427
1429
return PyErr_NoMemory ();
1428
1430
}
@@ -1454,6 +1456,7 @@ imaginary_add(PyObject *v, PyObject *w)
1454
1456
{
1455
1457
if (!PyImaginary_Check (v )) {
1456
1458
PyObject * tmp = v ;
1459
+
1457
1460
v = w ;
1458
1461
w = tmp ;
1459
1462
}
@@ -1468,7 +1471,6 @@ imaginary_add(PyObject *v, PyObject *w)
1468
1471
else if (real_to_double (& w , & b ) < 0 ) {
1469
1472
return w ;
1470
1473
}
1471
-
1472
1474
return PyComplex_FromDoubles (b , a );
1473
1475
}
1474
1476
@@ -1503,7 +1505,6 @@ imaginary_sub(PyObject *v, PyObject *w)
1503
1505
else if (real_to_double (& w , & b ) < 0 ) {
1504
1506
return w ;
1505
1507
}
1506
-
1507
1508
return PyComplex_FromDoubles (- b , a );
1508
1509
}
1509
1510
@@ -1512,6 +1513,7 @@ imaginary_mul(PyObject *v, PyObject *w)
1512
1513
{
1513
1514
if (!PyImaginary_Check (v )) {
1514
1515
PyObject * tmp = v ;
1516
+
1515
1517
v = w ;
1516
1518
w = tmp ;
1517
1519
}
@@ -1530,7 +1532,6 @@ imaginary_mul(PyObject *v, PyObject *w)
1530
1532
else if (real_to_double (& w , & b ) < 0 ) {
1531
1533
return w ;
1532
1534
}
1533
-
1534
1535
return PyImaginary_FromDouble (a * b );
1535
1536
}
1536
1537
@@ -1544,10 +1545,12 @@ imaginary_div(PyObject *v, PyObject *w)
1544
1545
if (b ) {
1545
1546
if (PyImaginary_Check (v )) {
1546
1547
double a = ((PyComplexObject * )(v ))-> cval .imag ;
1548
+
1547
1549
return PyFloat_FromDouble (a /b );
1548
1550
}
1549
1551
if (PyComplex_Check (v )) {
1550
1552
Py_complex a = ((PyComplexObject * )(v ))-> cval ;
1553
+
1551
1554
return PyComplex_FromDoubles (a .imag /b , - a .real /b );
1552
1555
}
1553
1556
if (real_to_double (& v , & a ) < 0 ) {
@@ -1562,6 +1565,7 @@ imaginary_div(PyObject *v, PyObject *w)
1562
1565
1563
1566
if (PyComplex_Check (w )) {
1564
1567
Py_complex b = ((PyComplexObject * )(w ))-> cval ;
1568
+
1565
1569
errno = 0 ;
1566
1570
b = _Py_rc_quot (a , b );
1567
1571
b = (Py_complex ){- b .imag , b .real };
@@ -1576,7 +1580,6 @@ imaginary_div(PyObject *v, PyObject *w)
1576
1580
return PyImaginary_FromDouble (a /b );
1577
1581
}
1578
1582
}
1579
-
1580
1583
PyErr_SetString (PyExc_ZeroDivisionError , "complex division by zero" );
1581
1584
return NULL ;
1582
1585
}
@@ -1592,6 +1595,7 @@ imaginary_conjugate_impl(PyComplexObject *self)
1592
1595
/*[clinic end generated code: output=247bb3742efd769d input=8dcd1c93a873c492]*/
1593
1596
{
1594
1597
Py_complex c = self -> cval ;
1598
+
1595
1599
c .imag = - c .imag ;
1596
1600
return PyImaginary_FromDouble (c .imag );
1597
1601
}
@@ -1606,6 +1610,7 @@ imaginary___getnewargs___impl(PyComplexObject *self)
1606
1610
/*[clinic end generated code: output=a587156eda821f7d input=da4b7e53915987d5]*/
1607
1611
{
1608
1612
Py_complex c = self -> cval ;
1613
+
1609
1614
return Py_BuildValue ("(d)" , c .imag );
1610
1615
}
1611
1616
0 commit comments