kopia lustrzana https://github.com/jamescoxon/dl-fldigi
29 wiersze
490 B
C++
29 wiersze
490 B
C++
#include <config.h>
|
|
|
|
#include "util.h"
|
|
|
|
/* Return the smallest power of 2 not less than n */
|
|
uint32_t ceil2(uint32_t n)
|
|
{
|
|
--n;
|
|
n |= n >> 1;
|
|
n |= n >> 2;
|
|
n |= n >> 4;
|
|
n |= n >> 8;
|
|
n |= n >> 16;
|
|
|
|
return n + 1;
|
|
}
|
|
|
|
/* Return the largest power of 2 not greater than n */
|
|
uint32_t floor2(uint32_t n)
|
|
{
|
|
n |= n >> 1;
|
|
n |= n >> 2;
|
|
n |= n >> 4;
|
|
n |= n >> 8;
|
|
n |= n >> 16;
|
|
|
|
return n - (n >> 1);
|
|
}
|