stack overflow error while performing recursion

the question is pow(x,n)
double positivePower(double x,int n,double res)
{
if(n==0)
{
return res;
}

return positivePower(x,n-1,res*x);

}
double negativePower(double x,int n,double res)
{
if(n==0)
{
return res;
}
return negativePower(x,n+1,res/x);
}

double myPow(double x, int n)
{
double res=1.00;
if(n<0)
{
return negativePower(x,n,res);
}
else
{
return positivePower(x,n,res);
}
}
Input:
0.00001
2147483647
Error:
AddressSanitizer:DEADLYSIGNAL

==33==ERROR: AddressSanitizer: stack-overflow on address 0x7ffd06232ff8 (pc 0x0000004017dc bp 0x7ffd06233000 sp 0x7ffd06233000 T0)
==33==ABORTING

Can anyone tell me why is it so. I had done my best to make it a tail recursion but still getting this error.

Comments (0)