3 ms·
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
by bazzargh 13y ago
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 http://en.wikipedia.org/wiki/Hamming_weight