Clutter Engine 0.0.1
Loading...
Searching...
No Matches
bit.inl
1
2
3namespace glm
4{
6 // highestBitValue
7
8 template<typename genIUType>
9 GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
10 {
11 genIUType tmp = Value;
12 genIUType result = genIUType(0);
13 while(tmp)
14 {
15 result = (tmp & (~tmp + 1)); // grab lowest bit
16 tmp &= ~result; // clear lowest bit
17 }
18 return result;
19 }
20
21 template<length_t L, typename T, qualifier Q>
26
28 // lowestBitValue
29
30 template<typename genIUType>
31 GLM_FUNC_QUALIFIER genIUType lowestBitValue(genIUType Value)
32 {
33 return (Value & (~Value + 1));
34 }
35
36 template<length_t L, typename T, qualifier Q>
37 GLM_FUNC_QUALIFIER vec<L, T, Q> lowestBitValue(vec<L, T, Q> const& v)
38 {
39 return detail::functor1<vec, L, T, T, Q>::call(lowestBitValue, v);
40 }
41
43 // powerOfTwoAbove
44
45 template<typename genType>
46 GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType value)
47 {
48 return isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
49 }
50
51 template<length_t L, typename T, qualifier Q>
56
58 // powerOfTwoBelow
59
60 template<typename genType>
61 GLM_FUNC_QUALIFIER genType powerOfTwoBelow(genType value)
62 {
63 return isPowerOfTwo(value) ? value : highestBitValue(value);
64 }
65
66 template<length_t L, typename T, qualifier Q>
71
73 // powerOfTwoNearest
74
75 template<typename genType>
76 GLM_FUNC_QUALIFIER genType powerOfTwoNearest(genType value)
77 {
78 if(isPowerOfTwo(value))
79 return value;
80
81 genType const prev = highestBitValue(value);
82 genType const next = prev << 1;
83 return (next - value) < (value - prev) ? next : prev;
84 }
85
86 template<length_t L, typename T, qualifier Q>
91
92}//namespace glm
GLM_FUNC_DECL bool isPowerOfTwo(genIUType v)
Definition scalar_integer.inl:160
GLM_FUNC_DECL genIUType highestBitValue(genIUType Value)
Definition bit.inl:9
GLM_FUNC_DECL genIUType lowestBitValue(genIUType Value)
Definition bit.inl:31
GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoBelow(genIUType Value)
GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoNearest(genIUType Value)
GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoAbove(genIUType Value)
Core features
Definition common.hpp:21
Definition _vectorize.hpp:7
Definition qualifier.hpp:35