summaryrefslogtreecommitdiff
path: root/src/utils/mathutils.h
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 /src/utils/mathutils.h
parent3c41c3e18872c1fccfc9a83343c81e97c5fa5787 (diff)
downloadmanaverse-db00f34d1c385c8ec007a077c2f78aef764d3bbb.tar.gz
manaverse-db00f34d1c385c8ec007a077c2f78aef764d3bbb.tar.bz2
manaverse-db00f34d1c385c8ec007a077c2f78aef764d3bbb.tar.xz
manaverse-db00f34d1c385c8ec007a077c2f78aef764d3bbb.zip
Add a bit constexpr.
Diffstat (limited to 'src/utils/mathutils.h')
-rw-r--r--src/utils/mathutils.h19
1 files changed, 7 insertions, 12 deletions
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);
}