Skip to content

Commit

Permalink
handle NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSaydakov committed Jan 24, 2024
1 parent e98561c commit e241813
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tdigest/include/tdigest_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tdigest(false, k, std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::i

template<typename T, typename A>
void tdigest<T, A>::update(T value) {
// check for NaN
if (std::isnan(value)) return;
if (buffer_.size() >= buffer_capacity_ - centroids_.size()) merge_new_values();
buffer_.push_back(centroid(value, 1));
++buffered_weight_;
Expand Down Expand Up @@ -89,7 +89,7 @@ uint64_t tdigest<T, A>::get_total_weight() const {
template<typename T, typename A>
double tdigest<T, A>::get_rank(T value) const {
if (is_empty()) throw std::runtime_error("operation is undefined for an empty sketch");
// check for NaN
if (std::isnan(value)) throw std::invalid_argument("operation is undefined for NaN");
if (value < min_) return 0;
if (value > max_) return 1;
// one centroid and value == min_ == max_
Expand Down

0 comments on commit e241813

Please sign in to comment.