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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression: use a precision that ensures no floating point issue #9163
Conversation
I don't think it's that easy. Have a look at https://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10 with this test function
the output is:
|
Hmm. Sorry I don't see. For me all values on top are wrong, and all on bottom are correct. So it seems to confirm the fix. What did I miss? |
The value of The documentation of max_digits10 says:
So, this means when serializing a double as string then by using max_digits10 (which is even higher than digits10 + 1) it's guaranteed that the double converted from the string is equal. With digits10 we lose precision. Look at this test code now:
The output is:
So, the question is whether the change could cause possible regressions elsewhere. |
Well, all that you wrote is perfectly correct and I agree with it. But IMO this is looking at the problem from the wrong side. 馃槈
Which is excellent. We have an inner precision better than the one we display. This is precisely what we want.
Again, I have no doubt that it internally is. And having displayed as 0.0 is excellent as this also proves that our display precision is compatible with internal precision.
True. But basically we do the opposite : string -> value -> string. And in this case this documentation doesn't apply. It even is the "opposite", we have issues using a more than max_digits10 value to string conversion. Which is normal.
But we need to lose precision in our case. 馃槈 This is a tradeoff to ensure we correctly display the user input.
I quickly checked and |
I have looked at the history of the file and at the very beginning there was no precision set. Later digits10 + 1 was set, then digits10 + 2 that caused some problems. The change was reverted until it was again set to digts10 + 2. This of course, caused again some problems so that it was reverted. However, I never found an explanation why digits10 +1 or +2 was used.
Not only. When saving it to a file then we have value -> string -> value. Doing some tests I couldn't find a case where the restored value has caused problems.
Then you missed the saving of a project. The call stack is:
But as said I couldn't find a problem I think it's fine to merge it. |
Yes, but this is actually part of a longer chain : string (user input) -> value (expression) -> string (document) -> value (expression) -> string (display). 馃槈
Yes I did. 馃槃 |
Not necessarily. I have created a test project with a spreadsheet. After the first saving I just opened the file and directly saved it again without having opened the spreadsheet. |
https://forum.freecad.org/viewtopic.php?t=77287
I should say I didn't really understand current code.
std::numeric_limits<double>::digits10
is exactly the maximum precision to ensure no floating point rounding issue.So setting it to
+ 1
is just making a step to the world of problems. 馃槃