So here's the current implementation of my power function.
pow(x, n) int x, n;
{
int r = 1;
int i;
for (i = 0; i < n; i++)
r *= x;
return (r);
}
The problem is how it only works for whole numbers & doesn't work with floats like pow(4, .5)
.
Of course, I've already tried changing everything to double
& I know how a standard library function exists. Also I've seen Floating point exponentiation without power-function, but none of the solutions were working nor what I wanted.
Here is the version, where I used double
s.
double pow(x, n)
double x, n;
{
double r = 1.;
int i;
for (i = 0; i < n; i++)
r *= x;
return (r);
}
It returns 1.
, when I use it as pow(4., .5)
.