88#include  "Python.h" 
99#include  "pycore_call.h"           // _PyObject_CallNoArgs() 
1010#include  "pycore_complexobject.h"  // _PyComplex_FormatAdvancedWriter() 
11- #include  "pycore_floatobject.h"    // _Py_convert_to_double () 
11+ #include  "pycore_floatobject.h"    // _Py_convert_int_to_double () 
1212#include  "pycore_long.h"           // _PyLong_GetZero() 
1313#include  "pycore_object.h"         // _PyObject_Init() 
1414#include  "pycore_pymath.h"         // _Py_ADJUST_ERANGE2() 
@@ -475,31 +475,31 @@ complex_hash(PyComplexObject *v)
475475}
476476
477477/* This macro may return! */ 
478- #define  TO_COMPLEX (obj , c ) \
479-     if (PyComplex_Check(obj)) \
480-         c = ((PyComplexObject *)(obj))->cval; \
481-     else if (to_complex (&(obj), &(c)) < 0) \
478+ #define  TO_COMPLEX (obj , c )                       \
479+     if (PyComplex_Check(obj))                    \
480+         c = ((PyComplexObject *)(obj))->cval;    \
481+     else if (real_to_complex (&(obj), &(c)) < 0) \
482482        return (obj)
483483
484484static  int 
485- to_float (PyObject  * * pobj , double  * dbl )
485+ real_to_float (PyObject  * * pobj , double  * dbl )
486486{
487487    PyObject  * obj  =  * pobj ;
488488
489489    if  (PyFloat_Check (obj )) {
490490        * dbl  =  PyFloat_AS_DOUBLE (obj );
491491    }
492-     else  if  (_Py_convert_to_double (pobj , dbl ) <  0 ) {
492+     else  if  (_Py_convert_int_to_double (pobj , dbl ) <  0 ) {
493493        return  -1 ;
494494    }
495495    return  0 ;
496496}
497497
498498static  int 
499- to_complex (PyObject  * * pobj , Py_complex  * pc )
499+ real_to_complex (PyObject  * * pobj , Py_complex  * pc )
500500{
501501    pc -> imag  =  0.0 ;
502-     return  to_float (pobj , & (pc -> real ));
502+     return  real_to_float (pobj , & (pc -> real ));
503503}
504504
505505/* Complex arithmetic rules implement special mixed-mode case: combining 
@@ -523,7 +523,7 @@ to_complex(PyObject **pobj, Py_complex *pc)
523523static  PyObject  * 
524524complex_add (PyObject  * v , PyObject  * w )
525525{
526-     if  (PyComplex_Check (w )) {
526+     if  (! PyComplex_Check (v )) {
527527        PyObject  * tmp  =  v ;
528528        v  =  w ;
529529        w  =  tmp ;
@@ -536,7 +536,7 @@ complex_add(PyObject *v, PyObject *w)
536536        Py_complex  b  =  ((PyComplexObject  * )(w ))-> cval ;
537537        a  =  _Py_c_sum (a , b );
538538    }
539-     else  if  (to_float (& w , & b ) <  0 ) {
539+     else  if  (real_to_float (& w , & b ) <  0 ) {
540540        return  w ;
541541    }
542542    else  {
@@ -559,19 +559,19 @@ complex_sub(PyObject *v, PyObject *w)
559559            errno  =  0 ;
560560            a  =  _Py_c_diff (a , b );
561561        }
562-         else  if  (to_float (& v , & a .real ) <  0 ) {
562+         else  if  (real_to_float (& v , & a .real ) <  0 ) {
563563            return  v ;
564564        }
565565        else  {
566-             a  =  (Py_complex ) {a .real , - b .imag };
567566            a .real  -=  b .real ;
567+             a .imag  =  - b .imag ;
568568        }
569569    }
570570    else  {
571571        a  =  ((PyComplexObject  * )(v ))-> cval ;
572572        double  b ;
573573
574-         if  (to_float (& w , & b ) <  0 ) {
574+         if  (real_to_float (& w , & b ) <  0 ) {
575575            return  w ;
576576        }
577577        a .real  -=  b ;
@@ -583,7 +583,7 @@ complex_sub(PyObject *v, PyObject *w)
583583static  PyObject  * 
584584complex_mul (PyObject  * v , PyObject  * w )
585585{
586-     if  (PyComplex_Check (w )) {
586+     if  (! PyComplex_Check (v )) {
587587        PyObject  * tmp  =  v ;
588588        v  =  w ;
589589        w  =  tmp ;
@@ -596,7 +596,7 @@ complex_mul(PyObject *v, PyObject *w)
596596        Py_complex  b  =  ((PyComplexObject  * )(w ))-> cval ;
597597        a  =  _Py_c_prod (a , b );
598598    }
599-     else  if  (to_float (& w , & b ) <  0 ) {
599+     else  if  (real_to_float (& w , & b ) <  0 ) {
600600        return  w ;
601601    }
602602    else  {
@@ -621,7 +621,7 @@ complex_div(PyObject *v, PyObject *w)
621621    else  {
622622        double  b ;
623623
624-         if  (to_float (& w , & b ) <  0 ) {
624+         if  (real_to_float (& w , & b ) <  0 ) {
625625            return  w ;
626626        }
627627        if  (b ) {
0 commit comments