diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index a829e4104..6f0dee123 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -917,14 +917,14 @@ NPY_NO_EXPORT void @type@ in2 = *(@type@ *)ip2; @type@ out; + if (in2 == 0) { + *((@type@ *)op1) = 1; + continue; + } if (in2 < 0 || in1 == 0) { *((@type@ *)op1) = 0; continue; } - if (in2 == 0) { - *((@type@ *)op1) = 1; - continue; - } out = in2 & 1 ? in1 : 1; in2 >>= 1; diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index d3d89f086..f2f94d7bf 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -430,6 +430,10 @@ class TestPower(TestCase): b = a ** a assert_equal(b, [437893890380859375, 437893890380859375]) + def test_integer_power_with_zero_exponent(self): + arr = np.arange(-10, 10) + assert_equal(np.power(arr, 0), np.ones_like(arr)) + class TestLog2(TestCase): def test_log2_values(self): |