Skip to content

binary_repr with large negative inputs #7168

Closed

Description

@lorenzMuller

binary_repr returns an error when a negative number that cannot be represented at the requested width is provided as input. When -2**width is input the output is erroneously zeros.

When inputting positive numbers that cannot be represented the output is the largest representable number; the negative analogue would be a sensible behaviour.

Example:
`
import numpy as np

np.binary_repr(-8, width=3)
np.binary_repr(-9, width=3)
`
my numpy version is 1.8.2

Activity

  1. gfyoung commented on Feb 2, 2016

    @gfyoung
    Contributor

    While your version of numpy is a little out of date, I can replicate that issue in 1.10.4.

  2. gfyoung commented on Feb 2, 2016

    @gfyoung
    Contributor

    Actually, in 1.10.4, np.binary_repr can properly represent -1, though admittedly the representations of other negative numbers is a little buggy.

  3. added a commit that references this issue on Mar 22, 2016
    2948e2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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