Better HN
topnewbestaskshowjobs
Log inSign up

sujitnair

2 karma · joined Dec 14, 2014 (11y ago) · 1 submissions

Submissions

comment 6y ago · link · parent

I find the following easier to visualize. If L is the lower bound and U is the upper bound, and if you visualize L, U as two points on the real number line, then:

left_of_U ( right_of_L (num)) = right_of_L ( left_of_U (num)) = clamped version of num between L and U.

Here, left_of_U = Math.min(num, U) and right_of_L = Math.max(num, L).