From 2a6babf9cce369c20c0a5ce89413b95ff2bcb4c2 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 18 Apr 2024 10:37:57 +0300 Subject: [PATCH] fix _Py_c_quot() instead --- Objects/complexobject.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 9b4092a61f956a7..b69ad6ab26274d5 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -105,7 +105,7 @@ _Py_c_quot(Py_complex a, Py_complex b) const double ratio = b.imag / b.real; const double denom = b.real + b.imag * ratio; r.real = (a.real + a.imag * ratio) / denom; - r.imag = (a.imag - a.real * ratio) / denom; + r.imag = (ratio ? a.imag - a.real * ratio : -a.real * ratio) / denom; } } else if (abs_bimag >= abs_breal) { @@ -177,12 +177,10 @@ c_powu(Py_complex x, long n) static Py_complex c_powi(Py_complex x, long n) { - if (n > 0) - return c_powu(x,n); - else { - c_1.imag = -copysign(0.0, x.imag); + if (n < 0) return _Py_c_quot(c_1, c_powu(x,-n)); - } + else + return c_powu(x,n); } double