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 */ |