def clip(x, min_val, max_val):
    """
    Clips x between min_ and max_val.

    Args:
        x (float): The input to be clipped.
        min_val (float): The min value for x.
        max_val (float): The max value for x.

    Returns:
        float: The clipped value.
    """
    return max(min_val, min(x, max_val))