title: Hacks for clamping integer to 0-255 and doubles to 0.0-1.0?
body: <p>Are there any branch-less or similar hacks for clamping an integer to the interval of 0 to 255, or a double to the interval of 0.0 to 1.0? (Both ranges are meant to be closed, i.e. endpoints are inclusive.)</p>
  
  <p>I'm using the obvious minimum-maximum check:</p>
  
  <pre><code>int value = (value &lt; 0? 0 : value &gt; 255? 255 : value);
  </code></pre>
  
  <p>but is there a way to get this faster -- similar to the "modulo" clamp <code>value &amp; 255</code>? And is there a way to do similar things with floating points?</p>
  
  <p>I'm looking for a portable solution, so preferably no CPU/GPU-specific stuff please.</p>