Clamp function for primitive types

Having been hit by min/max breakage, I’d vote to not repeat that.