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

Method rms

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

Option 3: define using fully qualified function name

Source from the content-addressed store, hash-verified

47
48// Option 3: define using fully qualified function name
49double math::averages::rms(std::span<const double> data)
50{
51 // The RMS or root mean square is defined as
52 // square root of the arithmetic mean of the squares of the elements.
53 double sum_squares{};
54 for (auto value : data)
55 sum_squares += square(value);
56
57 return data.empty()
58 ? std::numeric_limits<double>::quiet_NaN() // Or std::nan("")
59 : std::sqrt(sum_squares / data.size());
60}
61
62// Option 4: define using qualified name in outer namespace block
63namespace math

Callers

nothing calls this directly

Calls 3

squareFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected