The floating point version will work for integers up to about 2^51
(the width of mantissa). Beyond that integers cannot be represented
with perfect precision and will give you all the nastiness people have
pointed out.

A simple O(logn) implementation -
int64 pow_int64(int64 base, int64 pow) {
     if (pow == 0) return 1;
     int64 t = pow_int64(base, pow / 2);
     if (pow % 2 == 1) return base*t*t;
     else return t*t;
}

This is the recursive version. Can easily be converted to iterate
instead.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to