-
-
Notifications
You must be signed in to change notification settings - Fork 356
[FIX] limit double precision to 17 digits during write #4636
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
Conversation
👉 View analysis in DeepCode’s Dashboard |
@@ -60,7 +60,9 @@ namespace OpenMS | |||
class BK_PrecPolicy : public boost::spirit::karma::real_policies<T> | |||
{ | |||
public: | |||
static unsigned int precision(T) { return writtenDigits<T>(T()); } | |||
static unsigned int precision(T n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- bracket in new line
- add comment why this is sensible to do
@jpfeuffer I probably test if that fixes the issue before merging or? |
Sure. If you have workspace ready where the test data is, it should be quick. I wonder how many tests fail or if FuzzyDiff always catches the mini differences. |
in1: /home/travis/build/OpenMS/OpenMS/_build/src/tests/class_tests/openms/AccurateMassSearchEngine_test_319.tmp (line: 13, position/column: 14/36) in2: /home/travis/build/OpenMS/OpenMS/src/tests/class_tests/openms/data/AccurateMassSearchEngine_output1.featureXML (line: 13, position/column: 14/36) |
Yes, so the problem is, we used our writtenDigits() function before which returns std::numeric_limits::digits10, which is (in my opinion) not what you want if you want to read |
this is enough to represent the underlying single-precision float 36310.19921875 uniquely when reading it back in. |
// -> if scientific, subtract one | ||
return BK_PrecPolicy<T>::floatfield(n) ? | ||
std::numeric_limits<T>::max_digits10 - (floor(log10(n)) + 1) : | ||
std::numeric_limits<T>::max_digits10 - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why subtract one?
From the boost docu:
The extra two or three least-significant digits are 'noisy' and may be junk, but if you want to 'round-trip' - printing a value out as a decimal digit string and reading it back in - (most commonly during serialization and de-serialization) you must use os.precision(std::numeric_limits::max_digits10)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for scientifc notation only.
Let's see what the others think. Tested locally in addition:
|
So, me and @timosachsenberg figured that we: So the solution to b) would be to switch to scientific mode starting from < 0.1 |
if abs(N) < 0.1 |
2019e80
to
b3c9772
Compare
… normalization instead
did I get it right that the scientific notation has a fixed number of digits? And that lower number of written digits now works with luciphor? |
We set the precision to writtenDigits(), which is digits10 which is 15 for double. |
fixes #4627