How may we avoid overflow errors?

Thank you Steven! After I modified the first by following your comments, it work as well as the second:

class Solution:
    def myPow(self, x: float, n: int) -> float:
        if n == 0:
            return 1
        if n == 1:
            return x
        if n < 0 :
            return 1/self.myPow(x, -n)
        if n % 2 == 0:
            return (self.myPow(x*x, n//2)) 
        if n % 2 == 1:
            return x * (self.myPow(x*x, n//2))