Hello All,
I'm trying to find the n-th root of an equation using the power function. However, the n-th root that I want to find is not a nice round integer, it could best be described by a float/double value, which is always less than one. Let me provide a short excerpt of code:
for(i=2;i<maxYears;i++) {
TomsArray[i] = (pow((a/b),1/i)-1);
}
Where 'a' and 'b' represent double values, and i is an integer counter. As the loop counts upward, I need to take the (1/i)-th root of the (a/b) base. When I do this, my answers get rounded down to zero. That is, my array starts populating with zero values. If I manually cast the arguments to float or double, then I get some daunting compiler errors reminding me that I'm an idiot. In particular, if I cast the 1/i to float, then I receive the error: "ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second".
What I've found so far:
I saw this document:
http://cplusplus.com/reference/clibrary/cmath/pow/
but I had a hard time implementing it (e.g. specifying this power function as a double). I've been stuck on it for two hours now and since I've long since graduated from college, I don't have any resources or people to ask.
Request:
If somebody has a short example off hand, would they mind showing me how I can use a double base and double exponent? I don't need it applied to my particular scenario -- just an example demonstrating how one could solve it would be immensely helpful. I appreciate the help, and no rush on this, its nothing urgent.