Instead of saving register state and restoring it when result is exact, check...
Instead of saving register state and restoring it when result is exact, check at the begining of the function that the argument is 10^n and return n immediately before the register state is altered.