Clamp function fixed

Fixes  #4404