From 5a0ed6931094e33b74f196474199d2d516fc9c28 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 5 Jun 2017 10:05:03 +0000 Subject: [PATCH] compat.h: Add some more math stuff to support the next commit. git-svn-id: https://svn.eduke32.com/eduke32@6138 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/compat.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 2a487deb4..c21eb5281 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -643,11 +643,17 @@ using std::is_integral; # if CXXSTD >= 2014 using std::enable_if_t; using std::conditional_t; +using std::make_signed_t; +using std::make_unsigned_t; # elif CXXSTD >= 2011 template using enable_if_t = typename std::enable_if::type; template using conditional_t = typename std::conditional::type; +template +using make_signed_t = typename std::make_signed::type; +template +using make_unsigned_t = typename std::make_unsigned::type; # endif template @@ -938,6 +944,25 @@ CLAMP_DECL float fclamp2(float in, float min, float max) { return in >= max ? ma #ifdef __cplusplus +#if CXXSTD >= 2011 +template +struct DivResult +{ + T q; // quotient + T r; // remainder +}; +template +FORCE_INLINE CONSTEXPR DivResult divide(T lhs, T rhs) +{ + return DivResult{(T)(lhs / rhs), (T)(lhs % rhs)}; +} +template +FORCE_INLINE CONSTEXPR DivResult divrhs(T lhs) +{ + return divide(lhs, (T)base); +} +#endif + template CONSTEXPR size_t logbase(T n) {