-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
repr doesn't roundtrip for float32 dtype #9360
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
Comments
Frankly, I find this slightly disturbing, though it must have been there for many many years, should be fixed in any case in my opinion. |
If that'
8000
s the case, why is |
@eric-wieser: the |
Well explained. Seems like we should also expose those larger numbers in Also, can you cite a source for those numbers? |
As far as sources go, the C99 standard has the relevant formulas, in section 5.2.4.2.2p9: for binary -> decimal -> binary roundtrip for a binary format with precision p (which is what we want for I've never found non-paywalled proofs of those formulas, but they're not hard to prove directly: here are some proofs I wrote up last year, after getting annoyed at not finding anything online.
Sounds good in principle. The catch would be that C99 provides the precision numbers directly for
C11 does provide separate
Not right now. Naming things is hard. :-) |
Here you're using
Nope, they're hard-coded in the python code, calculated from |
Aargh, yes. Too many precisions. Yes, the number of bits in the significand, including the implicit bit where relevant.
Ah, right. I was making bad assumptions, then.
At a quick glance, it looks the same to me: for a (binary)precision-p binary format, eps should be 2**(1-p), so |
Uh oh!
There was an error while loading. Please reload this page.
It seems that the
np.float32
type doesn't have a round-trippablerepr
:Looking at the source, 8 significant digits are used for the
repr
of annp.float32
, but the IEEE 754 binary32 format requires 9 digits to roundtrip correctly.Perhaps this is intentional, but it seems surprising.
[Versions: Python 3.6.1, numpy 1.13.0, macOS 10.10.5]
The text was updated successfully, but these errors were encountered: