add pa_is_power_of_two() and pa_make_power_of_two() functions

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1684 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-08-22 00:20:13 +00:00
parent a0ad42a35f
commit b7b119ae00
2 changed files with 21 additions and 0 deletions

View file

@ -1208,3 +1208,21 @@ char *pa_truncate_utf8(char *c, size_t l) {
return c; return c;
} }
int pa_is_power_of_two(unsigned n) {
return !(n & (n - 1));
}
unsigned pa_make_power_of_two(unsigned n) {
unsigned j = n;
if (pa_is_power_of_two(n))
return n;
while (j) {
j = j >> 1;
n = n | j;
}
return n + 1;
}

View file

@ -97,4 +97,7 @@ int pa_snprintf(char *str, size_t size, const char *format, ...);
char *pa_truncate_utf8(char *c, size_t l); char *pa_truncate_utf8(char *c, size_t l);
int pa_is_power_of_two(unsigned n);
unsigned pa_make_power_of_two(unsigned n);
#endif #endif