def clip(x, minvalue, maxvalue):
    """
    clip the value of x between minvalue and maxvalue
    """
    if minvalue > x:
        return minvalue
    elif x < maxvalue:
        return x
    return maxvalue
