I have a problem defining a pow function for long long values, this is the code:
long long int pow( long long int base, long long int exp){
long long int count = 1;
for(int i=exp; i>=0; i--){
if(i==0) {break;}
if(exp==1) {count = count * base; break;}
count = count * base;
}
return count;
}
it is necessary to use iteration and not to be recursive, if I print the function for 2^i for I up to 63 from a certain moment on it computes 0, it is an overflow error? how can I avoid it?
question from:
https://stackoverflow.com/questions/65904515/overflow-pow-function-with-long-long 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…