0
votes

can power function be used to calulate the power of very large values like pow(200,200). also can it be used for long long int values ... pow(long long int,long long int).

i am getting this error /sources/tested.cpp: In function 'int main()':

/sources/tested.cpp:16: error: call of overloaded 'pow(long long int&, long long int&)' is ambiguous

/usr/include/bits/mathcalls.h:154: note: candidates are: double pow(double, double)

/usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:360: note: long double std::pow(long double, int)

/usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:356: note: float std::pow(float, int)

/usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:352: note: double std::pow(double, int) /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:348: note: long double std::pow(long double, long double)

/usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:344: note: float std::pow(float, float)

2

2 Answers

5
votes

If you're looking to do arbitrary precision math, you'll need to get a library for it. Likely, your platform doesn't have data types large enough to do so natively. Check out GNU MP.

1
votes

As you can see from the error messages, there is no pow function that works on two long long int values. The compiler tries to automatically convert the long long int values to something else (double or long etc.). but it can't unambiguously decide which function to take.

You can't use the standard pow function to compute very large numbers such as pow(200, 200), because the result doesn't fit in any data type for which the pow function is defined - you'll get an overflow or other 'wrong' answer.