Working on a program, and there’s one line of my code that is giving me issues. I was wondering if anyone here may know how to fix this one line of code:
long long x;
srand(time(NULL));
x = rand() % 1000;
long long range = pow (2, 60*(pow(2,x)-1)) ;
Whenever I run this I get an error stating that there is an ambiguous call to overload.
I did some research and it seems to have to do with different types (concerning the long long). I was thinking there may be a way to cast this in a different way in order to go around this issue, however I’m unsure of how to do this.
Would anyone happen to have any suggestions on what to do in order to get the second line of code working?
EDIT: I get the following errors:
main1.cpp:149: 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:
/usr/include/architecture/i386/math.h:343: note: candidate 1: double pow(double, double)
/usr/include/c++/4.2.1/cmath:357: note: candidate 2: float std::pow(float, float)
main1.cpp:149: 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:
/usr/include/architecture/i386/math.h:343: note: candidate 1: double pow(double, double)
/usr/include/c++/4.2.1/cmath:357: note: candidate 2: float std::pow(float, float)
With the method that Luchian suggested the following error that appears is the following:
main1.cpp:149: error: call of overloaded 'pow(int, long long int&)' is ambiguous
/usr/include/architecture/i386/math.h:343: note: candidates are: double pow(double, double)
/usr/include/c++/4.2.1/cmath:357: note: float std::pow(float, float)
/usr/include/c++/4.2.1/cmath:361: note: long double std::pow(long double, long double)
/usr/include/c++/4.2.1/cmath:365: note: double std::pow(double, int)
/usr/include/c++/4.2.1/cmath:369: note: float std::pow(float, int)
/usr/include/c++/4.2.1/cmath:373: note: long double std::pow(long double, int)
Use either:
or