Clamp function

Do you want something like this?