title: Does java have a clamp function?
body: <p>Suppose I have a <code>value</code>, I usually do this to "clamp" it to a range, here the range <code>[0..1]</code>. That is if it is below the range start, increase it to the range start, it above the range end, reduce it to the range end.</p>
  
  <pre><code>clampedValue = Math.max(0, Math.min(1, value));
  </code></pre>
  
  <p>Is there any built in function for clamping to a range?</p>