changed ipow to use exponentation by squaring