summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/localconsts.h2
-rw-r--r--src/utils/mathutils.h19
2 files changed, 9 insertions, 12 deletions
diff --git a/src/localconsts.h b/src/localconsts.h
index 7fa4fc381..91c2bb904 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -23,6 +23,7 @@
#define nullptr 0
#define final
#define override
+#define constexpr
#define A_DELETE(func)
#define A_DELETE_COPY(func)
#else
@@ -32,6 +33,7 @@
#if GCC_VERSION < 40700
#define final
#define override
+#define constexpr
//#define A_DELETE
//#define A_DELETE_COPY
#endif
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 1fc55e859..0472750d3 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -68,9 +68,9 @@ static const uint16_t crc_table[256] =
inline uint16_t getCrc16(const std::string &str) A_WARN_UNUSED;
inline float fastInvSqrt(float x) A_WARN_UNUSED;
inline float fastSqrt(const float x) A_WARN_UNUSED;
-inline float weightedAverage(const float n1, const float n2,
- const float w) A_WARN_UNUSED;
-inline int roundDouble(const double v) A_WARN_UNUSED;
+constexpr inline float weightedAverage(const float n1, const float n2,
+ const float w) A_WARN_UNUSED;
+constexpr inline int roundDouble(const double v) A_WARN_UNUSED;
inline int powerOfTwo(const int input) A_WARN_UNUSED;
inline uint16_t getCrc16(const std::string &str)
@@ -113,18 +113,13 @@ inline float fastSqrt(const float x)
return 1.0f / fastInvSqrt(x);
}
-inline float weightedAverage(const float n1, const float n2, const float w)
+constexpr inline float weightedAverage(const float n1, const float n2,
+ const float w)
{
- if (w < 0.0f)
- return n1;
-
- if (w > 1.0f)
- return n2;
-
- return w * n2 + (1.0f - w) * n1;
+ return w < 0.0f ? n1 : (w > 1.0f ? n2 : w * n2 + (1.0f - w) * n1);
}
-inline int roundDouble(const double v)
+constexpr inline int roundDouble(const double v)
{
return (v > 0.0) ? static_cast<int>(v + 0.5) : static_cast<int>(v - 0.5);
}