Added clamp method for constraining a value to lie within an interval.