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

Method rms

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

Option 3: define using fully qualified function name

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

squareFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected