title: Optimizing a floating point division and conversion operation
body: <p>I have the following formula </p>
  
  <pre><code>float mean = (r+b+g)/3/255.0f;
  </code></pre>
  
  <p>I want to speed it up. There are the following preconditions</p>
  
  <pre><code>0&lt;= mean &lt;= 1  and 0 &lt;= r,g,b &lt;= 255 and r, g, b are unsigned chars
  </code></pre>
  
  <p>so if I try to use the fact that >> 8 is like dividing by 256 and I use something like </p>
  
  <pre><code>float mean = (float)(((r+b+g)/3) &gt;&gt; 8);
  </code></pre>
  
  <p>this will always return 0. Is there a way to skip the costly float division and still end up with a mean between 0 and 1?</p>