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

Function geometric_mean

Examples/NoModules/Chapter 11/Ex11_07/math.cpp:33–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected