def quantize(x: int, q: int) -> int:
    """
    Will quantize a continuous or discrete range into steps of q
    where anything between 0 and q will be clipped to q.
    """
    return q * (x // q) if not 0 < x <= q else q