C++, fastest method of getting angle into a specified range?
<p>what's the fastest way of getting a variable into a given range? For example, make sure that an angle "double alpha" is always within (0.0, 2*Pi).</p>

<p>I found two solutions myself, one of them is much slower and the other looks way to complicated for such an easy task. There must be a better way, or not?</p>

<pre><code>//short, but very slow (so it's a no-go);
return asin(sin(alpha));

//much faster, but seems ugly (two while loops to change a variable? come on!)
while (alpha &lt; 0.0)
{
    alpha += 2.0 * M_PI;
}
while (alpha &gt;= 2.0 * M_PI)
{
    alpha -= 2.0 * M_PI;
}
return alpha;
</code></pre>
