aboutsummaryrefslogtreecommitdiff
path: root/aberth/util.h
blob: a276e2afc2729d1fc9aecef5260ad01ea777e1e1 (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
27
28
29
#pragma once

#include <iostream>
#include "defs.h"

using namespace std;


template <typename T>
constexpr static T clearLowestBit(T value) {
	return value & (value - 1);
}

template <typename T>
constexpr static bool ispow2(T value) {
	return clearLowestBit(value) == 0;
}

template <typename T>
constexpr static T ceil2(T value) {
	T value2 = clearLowestBit(value);
	if (value2 == 0) return value;

	while (true) {
		value = value2;
		value2 = clearLowestBit(value);
		if (value2 == 0) return value << 1;
	}
}