#pragma once
#include <cmath>

struct Stats {
  double sum = 0.0;
  double sumsq = 0.0;
  unsigned long n = 0L;
  double min = 0.0;
  double max = 0.0;


  inline void reset() {
    sum = 0;
    sumsq = 0;
    n = 0L;
    min = 0;
    max = 0;
  }

  inline double mean() {
    return sum / n;
  }

  inline double stddev() {
    return std::sqrt((sumsq - (sum * sum / n)) /
        (n - 1));
  }

  inline void sample(double s) {
    sum += s;
    sumsq += s * s;

    if (n == 0) {
      min = s;
      max = s;
    } else {
      if (min > s) min = s;
      if (max < s) max = s;
    }

    n += 1;
  }

  void dump();
};
