The power function called from ExA_07.cpp is defined in a different translation unit
| 1 | // The power function called from ExA_07.cpp is defined in a different translation unit |
| 2 | double 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 | } |