import math


def binary_search(arr, target):
    """
    Performs a binary search
    - Time complexity: O(log(n))
    - Space complexity: O(1)

    Args:
        arr (list): List of sorted numbers
        target (float): Target to find

    Returns:
        mid (int): Index of the target. Return -1 if not found
    """
    left = 0
    right = len(arr) - 1
    while left <= right:
        mid = math.floor((left + right) / 2)
        if arr[mid] < target:
            left = mid + 1
        elif arr[mid] > target:
            right = mid - 1
        else:
            return mid
    return -1