cgv
Loading...
Searching...
No Matches
integer.h
1#pragma once
2
3#include <type_traits>
4
5#include "fvec.h"
6
7#define IS_INTEGRAL_GUARD typename std::enable_if<std::is_integral<T>::value, bool>::type = true
8
10namespace cgv {
11namespace math {
12
14template<typename T, IS_INTEGRAL_GUARD>
15T is_power_of_two(T x) {
16 return x > 0 && (x & (x - 1)) == 0;
17}
18
20template<typename T, IS_INTEGRAL_GUARD>
21T next_power_of_two(T x) {
22 T pot = T(1);
23 while(x > pot)
24 pot <<= T(1);
25 return pot;
26}
27
29template<typename T, IS_INTEGRAL_GUARD>
30T next_multiple_k_greater_than_n(T k, T n) {
31 T remainder = k - (n % k);
32 if(n % k == T(0))
33 remainder = T(0);
34 return n + remainder;
35}
36
38template<typename T, IS_INTEGRAL_GUARD>
39T div_round_up(T a, T b) {
40 return (a + b - T(1)) / b;
41}
42
43template<typename T, cgv::type::uint32_type N, IS_INTEGRAL_GUARD>
44fvec<T, N> div_round_up(fvec<T, N> a, fvec<T, N> b) {
45 return (a + b - T(1)) / b;
46}
47
48} // namespace math
49} // namespace cgv
50
51#undef IS_INTEGRAL_GUARD
this header is dependency free
Definition print.h:11