def _binaryExponent(base, exponent):
    """Calculate base^exponent using the binary exponentiation algorithm.

    Depends on another function that verifies that all parameters are
    properly given.

    Arguments:
        base: Intiger or floating point number.
        exponent: Intiger number.

    Returns:
        base^exponent

    Raises
        RuntimeError: When trying to perform 0^0
    """
    # For an exponent <= 4 the algorithm makes no sense.
    # log_2(4) = 2 and 4 = 0b100, which will result in the exact same
    # process as the binary exponentiation algorithm.
    #
    # Avoiding it, we are actually saving a few operations (the bitwise and the
    # comparison).

    result = 1

    if (exponent == 0 and base == 0):
        raise RuntimeError("Magic error happened: 0^0.")
    elif (exponent == 0 and base != 0):
        return 1
    elif (exponent < 5):
        for _ in range(exponent):
            result *= base
    else:
        while (exponent > 0):
            # Current bit = 1
            if (exponent & 1):
                result *= base
            base *= base
            exponent = exponent >> 1

    return result