src/generics/functions.h

changeset 1430
6ce6d3da584f
parent 1429
80e8aaabeeed
equal deleted inserted replaced
1429:80e8aaabeeed 1430:6ce6d3da584f
35 { 35 {
36 return (::abs(a - ::floor(a)) < 0.00001) or (::abs(a - ::ceil(a)) < 0.00001); 36 return (::abs(a - ::floor(a)) < 0.00001) or (::abs(a - ::ceil(a)) < 0.00001);
37 } 37 }
38 38
39 template<typename T> 39 template<typename T>
40 T squared(T value) 40 auto constexpr squared(T value)
41 {
42 return ::pow(value, 2);
43 }
44
45 template<>
46 constexpr int squared<int>(int value)
47 { 41 {
48 return value * value; 42 return value * value;
49 } 43 }
50 44
51 // 45 //
68 62
69 // http://stackoverflow.com/a/18204188/3629665 63 // http://stackoverflow.com/a/18204188/3629665
70 template<typename T> 64 template<typename T>
71 constexpr int rotl10(T x) 65 constexpr int rotl10(T x)
72 { 66 {
73 return (((x) << 10) | (((x) >> 22) & 0x000000ff)); 67 return (x << 10) | ((x >> 22) & 0x000000ff);
74 } 68 }
75 69
76 template<typename T> 70 template<typename T>
77 constexpr int rotl20(T x) 71 constexpr int rotl20(T x)
78 { 72 {
79 return (((x) << 20) | (((x) >> 12) & 0x000000ff)); 73 return (x << 20) | ((x >> 12) & 0x000000ff);
80 } 74 }
81 75
82 // 76 //
83 // Get the amount of elements in something. 77 // Get the amount of elements in something.
84 // 78 //

mercurial