From 87e32bc3fc4f0251235f0a546e405b9ce3dce267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me?= Date: Mon, 1 Apr 2019 16:18:34 +0200 Subject: [PATCH] Added sureAbs() template so that we are sure to not cast a double to an int using ::abs() instead of std::abs(). --- utils.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils.hpp b/utils.hpp index 14088ab..376a6b4 100644 --- a/utils.hpp +++ b/utils.hpp @@ -14,6 +14,9 @@ template auto min(const T & a, const T2 & b) -> decltype(a | b) { return (a < b) ? T(a) : T(b); } template auto max(const T & a, const T2 & b) -> decltype(a | b) { return (a < b) ? T(b) : T(a); } +/// To be sure that floating point numbers won't be casted to integers in ::abs()... +template T sureAbs(const T & x) { return (x < T(0)) ? -x : x; } + template class C, class... Args> std::ostream& operator<<(std::ostream& os, const C& objs) {