@@ -26,8 +26,6 @@ class complex "PyComplexObject *" "&PyComplex_Type"
2626
2727/* elementary operations on complex numbers */
2828
29- static Py_complex c_1 = {1. , 0. };
30-
3129Py_complex
3230_Py_c_sum (Py_complex a , Py_complex b )
3331{
@@ -342,10 +340,12 @@ _Py_c_pow(Py_complex a, Py_complex b)
342340 return r ;
343341}
344342
343+ #define INT_EXP_CUTOFF 100
344+
345345static Py_complex
346346c_powu (Py_complex x , long n )
347347{
348- assert (n > 0 );
348+ assert (0 < n && n <= INT_EXP_CUTOFF );
349349 while ((n & 1 ) == 0 ) {
350350 x = _Py_c_prod (x , x );
351351 n >>= 1 ;
@@ -370,7 +370,7 @@ c_powi(Py_complex x, long n)
370370 else if (n < 0 )
371371 return _Py_rc_quot (1.0 , c_powu (x , - n ));
372372 else
373- return c_1 ;
373+ return ( Py_complex ){ 1. , 0. } ;
374374}
375375
376376double
@@ -760,7 +760,9 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z)
760760 errno = 0 ;
761761 // Check whether the exponent has a small integer value, and if so use
762762 // a faster and more accurate algorithm.
763- if (b .imag == 0.0 && b .real == floor (b .real ) && fabs (b .real ) <= 100.0 ) {
763+ if (b .imag == 0.0 && b .real == floor (b .real )
764+ && fabs (b .real ) <= INT_EXP_CUTOFF )
765+ {
764766 p = c_powi (a , (long )b .real );
765767 if (isfinite (a .real ) && isfinite (a .imag )) {
766768 _Py_ADJUST_ERANGE2 (p .real , p .imag );
0 commit comments