def fpow1(x, n):
    """
    Perform iterative fast exponentiation by squaring.

    :param x: the base to be exponentiated
    :param n: the target power value
    :return: x ^ n
    """
    if x == 0:
        if n == 0:
            return 1
        elif n > 0:
            return 0
        else:
            reason = '0.0 cannot be raised to a negative power'
            raise ZeroDivisionError(reason)
    if n < 0:
        x = 1 / x
        n = -n
    if n == 0:
        return 1
    y = 1
    while n > 1:
        if n % 2 == 0:
            x = x * x
            n = n // 2
        else:
            y = x * y
            x = x * x
            n = n // 2
    return x * y
