| 12 | namespace math::averages |
| 13 | { |
| 14 | double arithmetic_mean(std::span<const double> data) |
| 15 | { |
| 16 | // The arithmetic mean, the most commonly used average, |
| 17 | // is defined as the sum of all elements divided by the number of elements. |
| 18 | double sum {}; |
| 19 | for (auto value : data) |
| 20 | sum += value; |
| 21 | |
| 22 | return data.empty() |
| 23 | ? std::numeric_limits<double>::quiet_NaN() // Or std::nan("") |
| 24 | : sum / data.size(); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // Option 2: define in nested namespace blocks |