Skip to content
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

Fixed td_quantile returning NaN when 1 sample #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tdigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ static double td_internal_iterate_centroids_to_index(const td_histogram_t *h, co
double td_quantile(td_histogram_t *h, double q) {
td_compress(h);
// q should be in [0,1]
if (q < 0.0 || q > 1.0 || h->merged_nodes == 0) {
if (q < 0.0 || q > 1.0 || h->merged_nodes + h->unmerged_nodes == 0) {
return NAN;
}
// with one data point, all quantiles lead to Rome
if (h->merged_nodes == 1) {
if (h->merged_nodes + h->unmerged_nodes == 1) {
return h->nodes_mean[0];
}

Expand Down