code: public <T extends Average> T merge(T other) {
          if(Util.productGreaterThan(count, (long)Math.ceil(avg), Long.MAX_VALUE) ||
            Util.productGreaterThan(other.count(), (long)Math.ceil(other.average()), Long.MAX_VALUE)) {
              // the above computation is not correct as the sum of the 2 products can still lead to overflow
              // a non-weighted avg
              avg=avg + other.average() / 2.0;
          }
          else { // compute the new average weighted by count
              long total_count=count + other.count();
              avg=(count * avg + other.count() * other.average()) / total_count;
              count=total_count/2;
          }
          return (T)this;
      }
docs: Merges this average with another one