Fixed td_quantile returning NaN when 1 sample #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the t-digest has only a single sample, td_quantile returns NaN when it should return the value of the single sample.
The problem is that td_compress does not update the merged_nodes counter when there is only a single value.
Fix is to check on (merged_nodes + unmerged_nodes)
Steps to reproduce:
#include <cmocka.h>
td_histogram_t *h = td_new(50.0);
td_add(h, 0.2, 1);
assert_true(td_quantile(h, 0.5) == 0.2);