Ian Jauslin
summaryrefslogtreecommitdiff
blob: 13e2cf96896a5bc3d267d91484e3f43e5a11529b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <math.h>
#include "int_tools.h"

// return smallest power of 2 that is > x
int smallest_pow2(
  int x
){
  return ipow(2,((int)log2(x)+1));
}

// integer power
int ipow(
  int x,
  int n
){
  int out=1;
  while (n>0)
  {
    if (n%2==1){
      out*=x; 
    }
    n/=2;
    x*=x;
  }
  return out;
}