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 next_power_of_two(T x) {
16 T pot = T(1);
17 while(x > pot)
18 pot <<= T(1);
19 return pot;
20}
21
23template<typename T, IS_INTEGRAL_GUARD>
24T next_multiple_k_greater_than_n(T k, T n) {
25 T remainder = k - (n % k);
26 if(n % k == T(0))
27 remainder = T(0);
28 return n + remainder;
29}
30
32template<typename T, IS_INTEGRAL_GUARD>
33T div_round_up(T a, T b) {
34 return (a + b - T(1)) / b;
35}
36
37template<typename T, cgv::type::uint32_type N, IS_INTEGRAL_GUARD>
38fvec<T, N> div_round_up(fvec<T, N> a, fvec<T, N> b) {
39 return (a + b - T(1)) / b;
40}
41
42} // namespace math
43} // namespace cgv
44
45#undef IS_INTEGRAL_GUARD
the cgv namespace
Definition print.h:11