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

Function power

Examples/NoModules/Appendix A/ExA_07A/Power.cpp:2–8  ·  view source on GitHub ↗

The power function called from ExA_07.cpp is defined in a different translation unit

Source from the content-addressed store, hash-verified

1// The power function called from ExA_07.cpp is defined in a different translation unit
2double power(double x, int n)
3{
4 if (n < 0) return 1.0 / power(x, -n); // Deal with negative exponents
5 if (n == 0) return 1.0; // Recursion base case
6 const double y{ power(x, n / 2) }; // See Exercise 8-8 for an explanation
7 return y * y * (n % 2 == 1 ? x : 1.0);
8}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected