From 37d6d2f18a15dc88eefc9eef128be7ef76b69f42 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 16 Nov 2020 18:43:54 +0100 Subject: [PATCH] Add a sign() function for real numbers. --- include/lol/private/types/real.h | 1 + include/lol/private/types/real.ipp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/lol/private/types/real.h b/include/lol/private/types/real.h index 7eb6ea59..a9aa6221 100644 --- a/include/lol/private/types/real.h +++ b/include/lol/private/types/real.h @@ -157,6 +157,7 @@ public: template friend real_t fract(real_t const &x); template friend real_t degrees(real_t const &x); template friend real_t radians(real_t const &x); + template friend int sign(real_t const &x); // Additional functions template friend real_t franke(real_t const &x, diff --git a/include/lol/private/types/real.ipp b/include/lol/private/types/real.ipp index 867068fd..40b2abfa 100644 --- a/include/lol/private/types/real.ipp +++ b/include/lol/private/types/real.ipp @@ -1007,6 +1007,11 @@ template real_t radians(real_t const &x) return x * mul; } +template int sign(real_t const &x) +{ + return x.is_zero() ? 0 : x.is_negative() ? -1 : 1; +} + template real_t fast_log(real_t const &x) { /* This fast log method is tuned to work on the [1..2] range and