-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
'floor_in' can provide confusing results #589
Comments
Thank you for reporting this.
Yes. The problem is here: Instead, what you should to is to perform the computation in days:
I don't really think this is a bug in Numbat. It's rather a floating point precision problem, as you pointed out. If you think that there is something we can improve, please let me know. |
I have a few ideas, but, they are not so great :
|
Another approach could be to change the subtraction. Instead of using the left hand side to get the unit, we could always use the smaller unit instead. |
My first thought as well. 1/7 weeks is prone to floating point issues that 7 days is not. Going through the smaller of the two units seems reasonable, at least in the case when the ratio between them is an integer. (If it's something like 5/3, then you'll have floating point issues in either direction, although I don't see one direction being any worse than the other so this logic still might as well be applied universally.) |
After doing the operation with the smallest of the two unit, would it then be better to return the result as this unit or to keep the current exposed behavior and return the result in the unit of the left-hand-side quantity ? |
There is perhaps a third option which is to move from floats to rationals where possible. Then we'd have 1.5 weeks = 1.5*7 days = 21/2 days, and from there all the math works out fine because it's exact. Not sure how big a lift this would be. Even just recognizing when the user’s input is “rational enough” sounds challenging — 1.5? Yes. 0.1248? Probably not. |
Yes, that is a much better approach 👍. This also restores the (anti)commutative property of addition and subtraction, which is violated by the current behavior.
To restore (anti)commutativity, it should always return results in the same unit, no matter if we write
Relevant issue: #118. See also this comment: #180 (comment) |
Summary
floor_in
can provide confusing results (most likely due to a floating point precision problem)Steps to reproduce
Link to the steps in numbat's web interface
Expected Results
Actual Results
Setup
The text was updated successfully, but these errors were encountered: