From 2f571a0d9d90af44cb72a273498d3c95975d75cd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 18 Aug 2014 18:05:07 -0400 Subject: Common: Add a clamp function to math_utils.h --- src/common/math_util.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/common/math_util.h') diff --git a/src/common/math_util.h b/src/common/math_util.h index 65220fbd..b32e7bb1 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -6,11 +6,18 @@ #include "common/common.h" +#include #include namespace MathUtil { +template +inline T Clamp(const T val, const T& min, const T& max) +{ + return std::max(min, std::min(max, val)); +} + static const u64 DOUBLE_SIGN = 0x8000000000000000ULL, DOUBLE_EXP = 0x7FF0000000000000ULL, DOUBLE_FRAC = 0x000FFFFFFFFFFFFFULL, -- cgit v1.2.3