def clip(number: float, lower: float, upper: float) -> float:
    """Clip `number` to the closed interval [`lower`, `upper`].

    Args:
        number: Input value.
        lower: Lower bound.
        upper: Upper bound.

    Returns:
        Clipped value.
    """
    if lower > upper:
        lower, upper = upper, lower

    return max(lower, min(number, upper))