2014-12-15 21:04:08 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-07-19 16:22:22 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-12-15 21:04:08 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace MathUtil
|
|
|
|
{
|
|
|
|
|
|
|
|
#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
|
|
|
#define ROUND_DOWN(x, a) ((x) & ~((a) - 1))
|
|
|
|
|
2015-01-11 13:11:09 +00:00
|
|
|
template<class T>
|
|
|
|
inline void Clamp(T* val, const T& min, const T& max)
|
|
|
|
{
|
|
|
|
if (*val < min)
|
|
|
|
*val = min;
|
|
|
|
else if (*val > max)
|
|
|
|
*val = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline T Clamp(const T val, const T& min, const T& max)
|
|
|
|
{
|
|
|
|
T ret = val;
|
|
|
|
Clamp(&ret, min, max);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-15 21:04:08 +00:00
|
|
|
}
|