tag:blogger.com,1999:blog-6454006.post2158983571680343158..comments2024-01-16T14:32:49.175+00:00Comments on Arcane Sentiment: Function of the day: clampArcane Sentimenthttp://www.blogger.com/profile/04144052171693893368noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6454006.post-67642841760457003802012-08-29T16:43:25.219+00:002012-08-29T16:43:25.219+00:00Assuming low <= high, clamp is equivalent to me...Assuming low <= high, <i>clamp</i> is equivalent to <i>median</i>. And <i>median</i> doesn't care about argument order. Unfortunately verifying that low<=high at runtime makes <i>median</i> require more comparisons. With graphics code often performance sensitive this is not ideal. Also the correspondence is not immediate so the name <i>clamp</i> may be easier to read.<br /><br />Here's a language/compiler challenge: automatically optimize calls to median when some comparisons between the arguments can be proven, without the compiler having builtin support for median.<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6454006.post-91946588659596182422009-08-05T16:30:41.279+00:002009-08-05T16:30:41.279+00:00CLAMP comes up a lot with graphics. Another one th...CLAMP comes up a lot with graphics. Another one that has a name you "just need to know" is LERP aka linear interpolation.Anonymousnoreply@blogger.com