summary refs log tree commit diff
path: root/src/Math
diff options
context:
space:
mode:
Diffstat (limited to 'src/Math')
-rw-r--r--src/Math/Functions.hpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/Math/Functions.hpp b/src/Math/Functions.hpp
index 0cda6bd..e1e44e0 100644
--- a/src/Math/Functions.hpp
+++ b/src/Math/Functions.hpp
@@ -31,9 +31,11 @@ auto mod(A a, B b) -> decltype(a % b) {
     return (a % b + b) % b;
 }
 
+// Returns the sign of a number.
+// -1 if x < 0, 1 if x > 0, 0 if x == 0.
 template <typename T, typename R = T>
 R sign(T x) {
-    return x < 0 ? -1 : 1;
+    return (x > 0) - (x < 0);
 }
 
 // III. Utility functions.