I've been tasked to come up with a recursive solution to

X^n = (X^(n/2))^ 2 if n is even

X^n = (X * ((X^(n/2))^2)) if n is odd

now here's the function i've written so far

Code:

double RecursivePower3(double& baseValue, double expPower, double powerValue){
if (expPower == 0)
return 1;
if (expPower == 2)
return baseValue;
if (fmod(expPower, 2) == 0){ //then it's even
powerValue = pow(pow(baseValue,floor(expPower / 2)), 2);
return powerValue;
}
else{
powerValue = (baseValue * pow(pow(baseValue,floor(expPower / 2)), 2);
return powerValue;
}
}

where baseValue = X and expPower = n and are values entered in by the user.

can anyone tell me how this can be solved recursively?