Skip to content

Unexpected integer division/modulus result when using np.uint64 #10148

Closed

Description

@hanzhi713

Floating point result will appear if using numpy array of type uint64. This leads to numerically incorrect result when number is sufficiently large.
Tested on Python 3.5.2, numpy 1.13.3, on Windows 10 Build 17046.1000 (Insider Preivew)

import numpy as np
a = np.array([2], np.uint64)
print(31328281838316189 % a[0]) # which gives 0.0, not 1 as expected
print(31328281838316189 // a[0]) # which gives 1.56641409192e+16, not 15664140919158094 as expected

This problem will not occur if I replace uint64 with int64.

Activity

  1. hanzhi713 commented on Dec 2, 2017

    @hanzhi713
    Author

    It seems to be related to #5745 and #7126. This causes problems when doing large number arithmetic.

  2. ahaldane commented on Mar 23, 2019

    @ahaldane
    Member

    Reviewing this as part of my 10 random issues, as requested in a 3/20/19 request.

    I'm going to close this as a duplicate issue. See #12525 for the main discussion.

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