From b21e2b1f2ee6643fbd2e2a2eca0f219e7fa23110 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 24 Jan 2018 10:58:31 -0500 Subject: [PATCH] Add absf() to math.hpp --- include/math.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/math.hpp b/include/math.hpp index 815f3746..f35d3440 100644 --- a/include/math.hpp +++ b/include/math.hpp @@ -51,14 +51,18 @@ inline bool ispow2i(int n) { // float functions //////////////////// +inline float absf(float x) { + return (x < 0.f) ? -x : x; +} + /** Returns 1.0 for positive numbers and -1.0 for negative numbers (including positive/negative zero) */ inline float sgnf(float x) { - return copysignf(1.0, x); + return copysignf(1.f, x); } inline float eucmodf(float a, float base) { float mod = fmodf(a, base); - return mod < 0.0 ? mod + base : mod; + return (mod < 0.f) ? mod + base : mod; } inline float nearf(float a, float b, float epsilon = 1e-6) {