8000 Unexpected result for 32-bit right shift on uint32 · Issue #13106 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Unexpected result for 32-bit right shift on uint32 #13106
Closed
@javidcf

Description

@javidcf

Taken from this StackOverflow question: Why is (2^31) >> 32 not 0?

A 32-bit right shift applied to a uint32 array with the value 231 in it produces an array with the value 2147483648 instead of 0. Interestingly, when the operation is applied to a scalar with the same value the result is 0.

As discussed in the linked question, this probably has to do with 32-bit shifts of 32-bit values not being well-defined in C. However, this shouldn't condition the behavior of NumPy. Most importantly, the behavior should be consistent between arrays and scalars.

Reproducing code example:

import numpy as np

print(np.array([2 ** 31], dtype=np.uint32) >> 32)
# [2147483648]
print(np.array(2 ** 31, dtype=np.uint32) >> 32)
# 0

Error message:

NA

Numpy/Python version information:

1.15.4 3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0