17#ifndef TOOLBOX_UTIL_MATH_HPP
18#define TOOLBOX_UTIL_MATH_HPP
26inline namespace util {
31 return n > 0 && (
n & (
n - 1)) == 0;
37 return n <= 1 ? 1 : 1 << (
sizeof(
n) * 8 - std::countl_zero(
n - 1));
43 return n <= 1 ? 1 : 1 << (
sizeof(
n) * 8 - std::countl_zero(
n - 1));
66 bool empty() const noexcept {
return size_ == 0; }
67 std::size_t
size() const noexcept {
return size_; }
68 double mean() const noexcept {
return mean_; }
69 double sum2() const noexcept {
return sum2_; }
70 double min() const noexcept {
return min_; }
71 double max() const noexcept {
return max_; }
78 min_ = std::numeric_limits<double>::max();
79 max_ = std::numeric_limits<double>::min();
84 double delta{val - mean_};
85 mean_ += delta / size_;
86 sum2_ += delta * (val - mean_);
87 min_ = std::min(min_, val);
88 max_ = std::max(max_, val);
90 template <
typename... ArgsT>
91 void append(
double first, ArgsT... args)
noexcept
102 double min_{std::numeric_limits<double>::max()};
103 double max_{std::numeric_limits<double>::min()};
108 return v.size() > 1 ?
v.sum2() / (
v.size() - 1) : std::numeric_limits<double>::quiet_NaN();
113 return !
v.empty() ?
v.sum2() /
v.size() : std::numeric_limits<double>::quiet_NaN();
118 return std::sqrt(
var(
v));
123 return std::sqrt(
varp(
v));
134 return mean + 1.6448536 *
sd;
140 return mean + 2.3263479 *
sd;
146 return mean + 3.0902323 *
sd;
v append(1345, 1301, 1368, 1322, 1310, 1370, 1318, 1350, 1303, 1299)