diff options
| author | Mel <einebeere@gmail.com> | 2024-02-15 12:18:50 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2024-02-15 12:18:50 +0100 |
| commit | 39d5b006063f27effd4bf96a0a40f02aded7c8f5 (patch) | |
| tree | 37605c5781abf5e1774cf8e2b6b536ae936a9a5a /src | |
| parent | 92f63bbdbfc214849c203511bbcb1be0a4865588 (diff) | |
| download | meowcraft-39d5b006063f27effd4bf96a0a40f02aded7c8f5.tar.zst meowcraft-39d5b006063f27effd4bf96a0a40f02aded7c8f5.zip | |
Math::sign should return 0 for 0
Diffstat (limited to 'src')
| -rw-r--r-- | src/Math/Functions.hpp | 4 |
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. |
