I am the author of Programming Praxis. Thanks for reading! You can ask questions here at Stack Overflow, of course, but you are also welcome to ask questions in the comments section of Programming Praxis. To answer your questions:

First, it works because that's the mathematical definition of logarithms. To multiply two numbers, take their logarithms, add the logarithms together, then take the anti-logarithm of the sum; in programming terms: *x* × *y* = exp ( log(*x*) + log(*y*) ). The powering operation takes the logarithm of the base, multiplies the logarithm by the exponent, then takes the anti-logarithm of the product; in programming terms, *x* ^{y} = exp ( log(*x*) × *y* ).

Second, it is O(1) only if you cheat. There is only a single (constant) operation involving the exponent, so the operation is constant-time only with respect to the exponent. But arithmetic takes time, in fact arithmetic on *n*-bit numbers takes time log(*n*), but we ignore that. As a practical matter, computers only provide logarithms up to some small limit, which is usually 3.4 × 10^{38} for single-precision floats and 1.8 × 10^{308} for double-precision floats. Within that range, the functions used internally are close enough to constant-time that we say taking logarithms and exponents is O(1). If you use a big-decimal library such as GMP, with floats that are very much larger, it will be incorrect to say that the arithmetic is done in constant time. So I guess it depends on how precise you want to be.