Skip to content

uint64 and int in integer-division returns float #9833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PrometheusPi opened this issue Oct 6, 2017 · 4 comments
Closed

uint64 and int in integer-division returns float #9833

PrometheusPi opened this issue Oct 6, 2017 · 4 comments

Comments

@PrometheusPi
Copy link

When using uint64 data type with any (signed) integer data types in an integer divisions // the result is a float, not an int. For any other np.uint an integer is returned. Is this the expected behavior - if yes why? Or should this be casted to an int instead?

Example code:

import numpy as np

type(np.int64(12) // np.uint64(5))
# returns numpy.float64 (2.0) --> FLOAT value!

type(np.int64(12) // np.uint32(5))
# returns numpy.int64 (2)

type(np.uint64(12) // np.int64(5))
# returns numpy.float64 (2.0) --> FLOAT value!

type(np.uint64(12) // np.uint64(5))
# returns numpy.uint64 (2)

I am using python 3.4 with numpy 1.10.4 on OS X 10.11.6 and a python 3.4.3 with numpy 1.12.0b1 on Ubuntu 14.04.5 LTS.

@eric-wieser
Copy link
Member

The bug here is actually "When using np.uint64 and np.signed_integer in any arithmetic, the result is promoted to float64"

@shoyer
Copy link
Member

shoyer commented Oct 7, 2017

This is actually intentional, although you are certainly not the first person to be displeased with it.

Let's keep this discussion consolidated to #5745

@shoyer shoyer closed this as completed Oct 7, 2017
@PrometheusPi
Copy link
Author

@eric-wieser and @shoyer Thank you for your reply. The reference helped a lot in understanding the numpy strategy at this point.

@ax3l
Copy link
Contributor

ax3l commented Oct 9, 2017

Huh, so that design decision means for the above examples:

If we do int arithmetics, where an (u)int64 operation is precise up to 20 significant digits, numpy trades the potential range difference of the input of a factor 2x for a precision decrease to 15-16 significant digits in float64 🦉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants