Skip to content
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

Python 3.5 NumPy 1.10.0 rounding (issue?) #7355

Closed
jakirkham opened this issue Feb 27, 2016 · 8 comments
Closed

Python 3.5 NumPy 1.10.0 rounding (issue?) #7355

jakirkham opened this issue Feb 27, 2016 · 8 comments

Comments

@jakirkham
Copy link
Contributor

Not sure if this is a bug or there is simply a discrepancy between NumPy and Python. Though this is what I am seeing in some (not all) cases. FYI, similar (but not the exact same) behavior for np.float128.

>>> import numpy as np
>>> a = np.float64(0.47140452079103168)
>>> round(a, 4)
0.47139999999999999
>>> a = np.float64(0.47140452079103168)
>>> round(float(a), 4)
0.4714
>>> a = 0.47140452079103168
>>> round(a, 4)
0.4714
@njsmith
Copy link
Member

njsmith commented Feb 27, 2016

It's a discrepancy in repr implementations:

In [1]: a = np.float64(0.47140452079103168)

In [2]: round(a, 4)
Out[2]: 0.47139999999999999

In [3]: type(_2)
Out[3]: numpy.float64

In [4]: float(_2)
Out[4]: 0.4714

np.float64.__repr__ is showing more digits than float.__repr__.

Still arguably a bug -- notice that it's only the float64 scalar type that's affected; the array printer works correctly:

In [5]: np.array(round(a, 4))
Out[5]: array(0.4714)

@jakirkham
Copy link
Contributor Author

The float128 scalar type has this issue as well it just goes the other direction. Though I see your point about arrays. So, maybe just a floating point/complex representation issue then?

@anntzer
Copy link
Contributor

anntzer commented May 11, 2016

See #6136 too.

@NeilGirdhar
Copy link
Contributor

NeilGirdhar commented May 18, 2016

I think this is a duplicate of #6136. One of these should be closed. The other should be renamed: string representation of floating point numbers in arrays should not display extra digits.

Simpler test case:

In [37]: print(np.ones(1, dtype=np.float32) * (0.12345678901234567890))
[ 0.12345679104328155517578125]

In [38]: print(np.ones(1, dtype=np.float64) * (0.12345678901234567890))
[ 0.12345678901234567736988623209981597028672695159912109375]

First one should be "[0.12345678]". Second one should be "[0.123456789012345678]".

yingzong pushed a commit to yingzong/numpy that referenced this issue Aug 7, 2016
prints distinguishing parentheses for scalar types
addresses issue numpy#7355, numpy#7913, related to numpy#6908
@ron819
Copy link

ron819 commented Nov 15, 2018

I think this one is no longer an issue

@rgommers
Copy link
Member

Thanks @ron819, indeed fixed.

@charris
Copy link
Member

charris commented Nov 15, 2018

Seems broken?

It's just how arrays are printed. The printing precision can be set, but by default it isn't large in order that more array elements may be displayed. The value is fine.

In [4]: (np.ones(1, dtype=np.float64) * (0.12345678901234567890))[0]
Out[4]: 0.12345678901234568

@SamWildmo
Copy link

@charris better to open a new ticket this one is very old

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

8 participants