Add clamp function

Request in issue 10039

http://d.puremagic.com/issues/show_bug.cgi?id=10039