summaryrefslogtreecommitdiff
path: root/src/utils/mathutils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/mathutils.h')
-rw-r--r--src/utils/mathutils.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 69267186c..3fa7ad002 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -24,6 +24,7 @@
#define UTILS_MATHUTILS_H
#include <string>
+#include <cmath>
#include "localconsts.h"
@@ -63,6 +64,60 @@ static const uint16_t crc_table[256] =
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
+static const int square_roots[1000] =
+{
+ 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
+ 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
+ 11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
+ 12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,
+ 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,
+ 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
+ 14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,
+ 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
+ 16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,
+ 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
+ 17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
+ 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
+ 18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
+ 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
+ 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
+ 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
+ 20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
+ 21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
+ 21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,
+ 22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,
+ 22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,
+ 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
+ 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,
+ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
+ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
+ 24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
+ 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
+ 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
+ 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31
+};
+
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;
@@ -130,4 +185,11 @@ inline int powerOfTwo(const unsigned int input)
return value;
}
+inline int fastSqrtInt(const unsigned int n)
+{
+ if (n < 1000)
+ return square_roots[n];
+ return sqrt(n);
+}
+
#endif // UTILS_MATHUTILS_H