def two_way_clamp(lower, upper, value):
    """ A function that accepts a lower and upper bound and a value
        and will return the value if it is between the bounds, or it
        will return the clamped value.

        >>> two_way_clamp(100, 500, 250)
        250

        >>> two_way_clamp(100, 500, -40)
        100

        >>> two_way_clamp(-100, -500, 0)
        -100
    """
    if lower > upper:
        upper, lower = lower, upper
    return max(lower, min(upper, value))
