Skip to content

BUG: shift with a negative number should fail #13898

Open

Description

@mattip

xref gh-13739

A negative shift is undefined in C. Python raises a ValueError, numpy returns the undefined values. We should at least warn, and probably raise an Error.

>>> a = np.arange(4)
>>> 10 << -1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative shift count
>>> a << -1
array([-9223372036854775808,                    0, -9223372036854775808,
                          0])

Activity

  1. mattip commented on Sep 18, 2023

    @mattip
    MemberAuthor

    The last example now returns array([0, 0, 0, 0]), but should it raise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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