-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
ZeroDivisionError when getting the __repr__ if nominal value is too small #135
Comments
Wow, interesting. Thanks for the concise but detailed report. A short traceback could be useful too, if you can add one. I am not close to a computer, but I'll have a look soon: I don't like surprising behaviors. :) |
Oh right, certainly. Here's the traceback.
it happens inside the |
We stumbled upon the same issue recently ( |
I'm not working on this project anymore, but there are new, active maintainers, who hopefully can look at this, but from the look of it, I'm wondering if the values that the code is manipulating aren't very small (close to underflow). If you have a minimal example that can reproduce this, that could help. Otherwise, just exploring this possibility (very negative |
The original example provided at the beginning of the issue still raises a from uncertainties import ufloat
a = 1e-324
b = 3e-324
assert a < b
print(ufloat(a, 0.0)) # OK
print(ufloat(b, 0.0)) # ZeroDivisionError
(Same outcome in python 3.12) |
Perhaps this is a very obscure bug but it does exist.
When running the following block of code:
It will throw a ZeroDivisionError at the print line.
I understand this is because, when converting the variable into a string using
v.__repr__()
it will attempt to factorize out the 1E-323 from both the v.n and the v.s.It seems that python would only complain about division by zero when n is between [2.5E324, 12.5E324), making it a very specific and obscure problem, which is perhaps why I'm the first person to file an issue for it
I was working with a large enough dataset to hit upon this weird bug.
I know a few ways to workaround this problem on my own (choose all values <12.5E-324 and then set them to zero); but do you think there's a way to write the
__repr__
in such a way to avoid future occurrences of this?Side note:
Interestingly while testing the behaviour, I found out that python rounds all numbers above 2.5E-324 to the nearest multiple of 5E-324. I guess this is the resolution of IEEE-754 numbers?
The text was updated successfully, but these errors were encountered: