summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-11-17 23:03:51 +0300
committerAndrei Karas <akaras@inbox.ru>2012-11-17 23:03:51 +0300
commitdb00f34d1c385c8ec007a077c2f78aef764d3bbb (patch)
tree8004470e320d9dc625d6f78c479b94ac4cc75177
parent3c41c3e18872c1fccfc9a83343c81e97c5fa5787 (diff)
downloadmanaplus-db00f34d1c385c8ec007a077c2f78aef764d3bbb.tar.gz
manaplus-db00f34d1c385c8ec007a077c2f78aef764d3bbb.tar.bz2
manaplus-db00f34d1c385c8ec007a077c2f78aef764d3bbb.tar.xz
manaplus-db00f34d1c385c8ec007a077c2f78aef764d3bbb.zip
Add a bit constexpr.
-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);
}