summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorprithvitewatia <42640176+prithvitewatia@users.noreply.github.com>2022-06-17 21:02:12 +0530
committerPrithvi <prithvisinghtewatia@gmail.com>2022-06-17 21:13:09 +0530
commit2805164576db9b3c78e98d8c93469e9023ce43ea (patch)
treea09c7564363b6206c59f9e89a9b764c36032ffdb /numpy
parent4f0d592d0c8865db7c570c489b442c981bc430f4 (diff)
downloadnumpy-2805164576db9b3c78e98d8c93469e9023ce43ea.tar.gz
Apply suggestions from code review
Co-authored-by: Matti Picus <matti.picus@gmail.com> Co-authored-by: Ivan Gonzalez <scratchmex@gmail.com>
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/npymath/npy_math_complex.c.src40
-rw-r--r--numpy/core/tests/test_umath.py6
2 files changed, 20 insertions, 26 deletions
diff --git a/numpy/core/src/npymath/npy_math_complex.c.src b/numpy/core/src/npymath/npy_math_complex.c.src
index 55a448866..a7ccd054d 100644
--- a/numpy/core/src/npymath/npy_math_complex.c.src
+++ b/numpy/core/src/npymath/npy_math_complex.c.src
@@ -462,32 +462,26 @@ npy_cpow@c@ (@ctype@ a, @ctype@ b)
*/
else if (ar == 0. && ai == 0.) {
/*
- * If br > 0 then result is 0 but contains sign opposite
- * of bi.
- * Else the result is undefined and we return (nan,nan)
+ * If the real part of b is positive (br>0) then this is
+ * the zero complex with positive sign on both the
+ * real and imaginary part.
*/
if (br > 0) {
- if (bi < 0) {
- return npy_cpack@c@(0., 0.);
- }
- else {
- return npy_cpack@c@(0., -0.);
- }
-
- }
- else {
- /*
- * Raising an invalid and returning
- * (nan, nan)
- */
- volatile @type@ tmp = NPY_INFINITY@C@;
- r = npy_cpack@c@(NPY_NAN@C@, NPY_NAN@C@);
-
- /* Raise invalid */
- tmp -= NPY_INFINITY@C@;
- ar = tmp;
- return r;
+ return npy_cpack@c@(0., 0.);
}
+ /* else we are in the case where the
+ * real part of b is negative (br<0).
+ * Here we should return a complex nan
+ * and raise FloatingPointError: invalid value...
+ */
+
+ /* Raise invalid value by calling inf - inf*/
+ volatile @type@ tmp = NPY_INFINITY@C@;
+ tmp -= NPY_INFINITY@C@;
+ ar = tmp;
+
+ r = npy_cpack@c@(NPY_NAN@C@, NPY_NAN@C@);
+ return r;
}
if (bi == 0 && (n=(npy_intp)br) == br) {
if (n == 1) {
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 1e6d18f6a..12b36f476 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -840,7 +840,7 @@ class TestPower:
# Testing 0^{Non-zero} issue 18378
def test_zero_power_nonzero(self):
- zero = np.array([0.0j])
+ zero = np.array([0.0+0.0j])
cnan = np.array([complex(np.nan, np.nan)])
def assert_complex_equal(x, y):
@@ -851,8 +851,8 @@ class TestPower:
assert_complex_equal(np.power(zero, 1+4j), zero)
assert_complex_equal(np.power(zero, 2-3j), zero)
#Testing zero values when real part is greater than zero
- assert_complex_equal(np.power(zero, 1+1j), -zero)
- assert_complex_equal(np.power(zero, 1+0j), -zero)
+ assert_complex_equal(np.power(zero, 1+1j), zero)
+ assert_complex_equal(np.power(zero, 1+0j), zero)
assert_complex_equal(np.power(zero, 1-1j), zero)
#Complex powers will negative real part or 0 (provided imaginary
# part is not zero) will generate a NAN and hence a RUNTIME warning