Skip to content

BUG: Incorrect __ipow__() result for array_api arrays when self is -0. or -inf, and other=0.5 #21213

@honno

Description

@honno

Describe the issue:

The Array API spec has the following special case __pow__()/ __ipow__()

If x1_i is -0, x2_i is greater than 0, and x2_i is not an odd integer value, the result is +0.

array_api arrays currently follow this special case for __pow__()__ipow__() seems to likewise follow this case except when x2_i=.5, where a negative 0 is returned instead. cc @asmeurer @seberg

Also discovered a similar problem when self=-inf #21213 (comment)

Reproduce the code example:

>>> x1 = xp.asarray(-0.)
>>> x2 = xp.asarray(0.5)
>>> x1 ** x2
Array(0., dtype=float64)
>>> x1 **= x2
>>> x1
Array(-0., dtype=float64)  # should be positive 0
...
>>> x3 = xp.asarray(-0.)
>>> x4 = xp.asarray(2.)
>>> x3 **= x4; x3
Array(0., dtype=float64)  # as expected
...
>>> x5 = xp.asarray(-0.)
>>> x6 = xp.asarray(2.5)
>>> x5 **= x6; x5
Array(0., dtype=float64)  # as expected
...
>>> x7 = xp.asarray(-0.)
>>> x8 = xp.asarray(.6)
>>> x7 **= x8; x7
Array(0., dtype=float64)  # as expected

Error message:

No response

NumPy/Python version information:

1.22.3 3.8.12 (default, Mar 13 2022, 19:12:08)
[GCC 9.4.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions