src/generics/functions.h

changeset 1411
b48f3fd2664b
parent 1390
3eace926af7f
child 1419
f7c53002a990
--- a/src/generics/functions.h	Tue Jun 19 22:00:46 2018 +0300
+++ b/src/generics/functions.h	Tue Jun 19 22:45:10 2018 +0300
@@ -118,24 +118,13 @@
 }
 
 /*
- * Extracts the sign of x.
+ * Extracts the sign of 'value'.
+ * From: https://stackoverflow.com/q/1903954
  */
 template<typename T>
-T sign(T x)
+int sign(T value)
 {
-	if (isZero(x))
-		return {};
-	else
-		return x / qAbs(x);
-}
-
-template<>
-inline int sign(int x)
-{
-	if (x == 0)
-		return 0;
-	else
-		return x / qAbs(x);
+	return (0 < value) - (value < 0);
 }
 
 /*

mercurial