News for hackers. Stuff that matters.
Re:Helping a stranger, and why you should understand NP-comp... by bazzargh on Monday November 04, 2013 @04:12PM (#6671201)
Another way to reduce the number of loops:

          for (int q2 = 1; q2 <= 256; q2 <<= 1)
            if (output * r1 * r2 * q1 * q2 == input * f1 * f2)
This doesn't need a loop. Set q2 directly and test if it is a power of 2.

     n2 = input * f1 * f2;
     d2 = output * r1 * r2 * q1;
     q2 = n2/d2;
     if (__builtin_popcount(q2) == 1 && q2 * d2 == n2) {
... taking advantage of the fact that calculating the Hamming weight of q2 doesn't need a loop.

http://en.wikipedia.org/wiki/Hamming_weight

There are no comments on this comment yet.