hughsk / clamp

Clamp a value between two other values.
MIT License
39 stars 5 forks source link

Avoid unnecessary comparisons #8

Closed twhb closed 6 years ago

twhb commented 7 years ago

Performance optimization. When, for example, value === min, only two comparisons are run: min <= max and value <= min. Before, three comparisons were run: min < max, value < min, and value > max. Same reasoning for all other insertions of =.