def is_perfect_square(num):
    """Test whether a given number is a perfect square.

    Tests whether a given number is a perfect square or not based
    on the Babylonian method for computing square roots.

    Args:
        num (int): The number to test whether it is a perfect square

    Returns:
        bool: True if num is a perfect square, otherwise False

    """

    if num < 0:
        return False
    if num == 0 or num == 1:
        return True

    x = num // 2
    y = {x}
    while x * x != num:
        x = (x + (num // x)) // 2
        if x in y:
            return False
        y.add(x)
    return True