src/generics/functions.h

changeset 1411
b48f3fd2664b
parent 1390
3eace926af7f
child 1419
f7c53002a990
equal deleted inserted replaced
1410:e76e219c48e9 1411:b48f3fd2664b
116 { 116 {
117 return vector.size(); 117 return vector.size();
118 } 118 }
119 119
120 /* 120 /*
121 * Extracts the sign of x. 121 * Extracts the sign of 'value'.
122 */ 122 * From: https://stackoverflow.com/q/1903954
123 template<typename T> 123 */
124 T sign(T x) 124 template<typename T>
125 { 125 int sign(T value)
126 if (isZero(x)) 126 {
127 return {}; 127 return (0 < value) - (value < 0);
128 else
129 return x / qAbs(x);
130 }
131
132 template<>
133 inline int sign(int x)
134 {
135 if (x == 0)
136 return 0;
137 else
138 return x / qAbs(x);
139 } 128 }
140 129
141 /* 130 /*
142 * Returns the maximum of a single parameter (the parameter itself). 131 * Returns the maximum of a single parameter (the parameter itself).
143 */ 132 */

mercurial