pow function with tail recursion