MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / geometric_mean

Function geometric_mean

Examples/Modules/Chapter 11/Ex11_07/math.cpp:32–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 namespace averages
31 {
32 double geometric_mean(std::span<const double> data)
33 {
34 // The geometric mean of n elements
35 // is defined as the n-th root of the product of all n elements
36 double product{ 1 };
37 for (auto value : data)
38 product *= value;
39
40 return data.empty()
41 ? std::numeric_limits<double>::quiet_NaN()
42 : std::pow(product, 1.0 / data.size());
43 }
44 }
45}
46

Callers 1

mainFunction · 0.70

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected