Skip to content

uint64 modulo arithmetic broken (Trac #1940) #2533

Closed

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1940 on 2011-08-22 by trac user AngerMCS, assigned to unknown.

Running numpy 1.6.0 on python 3.2.1 both compiled from source.

uint64(-1)%2 is returning 0.0 which is obviously incorrect.

Also when using uint64, modulo is returning a a float64 which is illogical since it can never return anything other than a uint64.

Python 3.2.1 (default, Jul 20 2011, 15:59:19)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from numpy import uint64
uint64(-1)
18446744073709551615
a = uint64(-1)
a
18446744073709551615
hex(a)
'0xffffffffffffffff'
a%2
0.0

Activity

  1. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @charris wrote on 2011-08-22

    I suspect this is another case of the 2 being treated as signed, hence the promotion to float64, which has insufficient precision. This also shows up in the shift operators, but there things are (were) promoted to objects. These ufuncs probably need special treatment of their arguments.

  2. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @charris wrote on 2011-08-22

    Note:

    In [2]: uint64(-1) % uint64(2)
    Out[2]: 1
    

    So probably what should happen in the original case is an error message on account of the promotion of kinds.

  3. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @mwiebe wrote on 2011-08-22

    I've got things rigged up now so each ufunc can define its own type promotion function, see here:

    https://github.com/m-paradox/numpy/blob/missingdata/numpy/core/include/numpy/ufuncobject.h#L191

    This can probably be special-cased using this mechanism.

  4. charris commented on Feb 21, 2014

    @charris
    Member

    Need to look into that...

  5. seberg commented on Nov 19, 2022

    @seberg
    Member

    Closing in favor of the linked gh-12525: This is a promotion issue.

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