def clip(val, minimum, maximum):
    """ Clips / limits a value to a specific range.
        Arguments:
            val: value to be limited
            minimum: minimum allowed value
            maximum: maximum allowed value
    """
    return min(max(val, minimum), maximum)