On Sat, Jan 29, 2011 at 12:07:12PM +0100, Philipp Überbacher wrote: > Took me a while to figure out that libm is part of glibc :) It isn't. But it lives in /lib, not /usr/lib > > k = (int)(log2(x) + 1e-6) > > log2() suffers from the same problem? I somewhat dislike the idea of > adding a constant. Everything floating point 'suffers from the same problem'. Even addition. (1/3.0 + 1/3.0 + 1/3.0 == 1.0) doesn't have to result in true. > > int m, k; > > for (k = 0, m = 1; m < x; k++, m <<= 1); > > > > which will round up if x is not a power of 2. > > Neat. I thought about it myself yesterday but my ideas weren't exactly > brilliant. One idea was to divide by 2, the other to use a small > lookup table for powers of 2. I don't really know about efficiency, but > I guess bit shifting is as efficient as it gets? It's a single CPU cycle on most processors, and on some (e.g. ARM) it can even be combined with other instructions. Ciao, -- FA There are three of them, and Alleline. _______________________________________________ Linux-audio-user mailing list Linux-audio-user@xxxxxxxxxxxxxxxxxxxx http://lists.linuxaudio.org/listinfo/linux-audio-user