aboutsummaryrefslogtreecommitdiff
path: root/Client/ThirdParty/fix32
diff options
context:
space:
mode:
Diffstat (limited to 'Client/ThirdParty/fix32')
-rw-r--r--Client/ThirdParty/fix32/fix32.cpp0
-rw-r--r--Client/ThirdParty/fix32/fix32.h7
-rw-r--r--Client/ThirdParty/fix32/fix32.hpp161
3 files changed, 161 insertions, 7 deletions
diff --git a/Client/ThirdParty/fix32/fix32.cpp b/Client/ThirdParty/fix32/fix32.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Client/ThirdParty/fix32/fix32.cpp
+++ /dev/null
diff --git a/Client/ThirdParty/fix32/fix32.h b/Client/ThirdParty/fix32/fix32.h
deleted file mode 100644
index fb3d65c..0000000
--- a/Client/ThirdParty/fix32/fix32.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-// -2,147,483,648 to 2,147,483,647
-typedef int64_t fix32_t;
-
diff --git a/Client/ThirdParty/fix32/fix32.hpp b/Client/ThirdParty/fix32/fix32.hpp
new file mode 100644
index 0000000..7999ad4
--- /dev/null
+++ b/Client/ThirdParty/fix32/fix32.hpp
@@ -0,0 +1,161 @@
+#pragma once
+
+#include <stdint.h>
+extern "C" {
+#include "math-sll/math-sll.h"
+}
+
+typedef sll fixed32_t;
+
+// Q32.32
+class Fix32
+{
+public:
+ sll value;
+
+ inline Fix32() { value = 0; }
+ inline Fix32(const Fix32 &inValue) { value = inValue.value; }
+ inline Fix32(const float inValue) { value = dbl2sll(inValue); }
+ inline Fix32(const double inValue) { value = dbl2sll(inValue); }
+ inline Fix32(const int32_t inValue) { value = int2sll(inValue); }
+ inline Fix32(const sll inValue) { value = inValue; }
+
+ inline operator sll() const { return value; }
+ inline operator double() const { return sll2dbl(value); }
+ inline operator float() const { return (float)sll2dbl(value); }
+ inline operator int32_t() const { return (int32_t)sll2int(value); }
+
+ inline Fix32 & operator=(const Fix32 &rhs) { value = rhs.value; return *this; }
+ inline Fix32 & operator=(const sll rhs) { value = rhs; return *this; }
+ inline Fix32 & operator=(const double rhs) { value = dbl2sll(rhs); return *this; }
+ inline Fix32 & operator=(const float rhs) { value = (float)dbl2sll(rhs); return *this; }
+ inline Fix32 & operator=(const int32_t rhs) { value = int2sll(rhs); return *this; }
+
+ inline Fix32 & operator+=(const Fix32 &rhs) { value += rhs.value; return *this; }
+ inline Fix32 & operator+=(const sll rhs) { value += rhs; return *this; }
+ inline Fix32 & operator+=(const double rhs) { value += dbl2sll(rhs); return *this; }
+ inline Fix32 & operator+=(const float rhs) { value += (float)dbl2sll(rhs); return *this; }
+ inline Fix32 & operator+=(const int32_t rhs) { value += int2sll(rhs); return *this; }
+
+ inline Fix32 & operator-=(const Fix32 &rhs) { value -= rhs.value; return *this; }
+ inline Fix32 & operator-=(const sll rhs) { value -= rhs; return *this; }
+ inline Fix32 & operator-=(const double rhs) { value -= dbl2sll(rhs); return *this; }
+ inline Fix32 & operator-=(const float rhs) { value -= (float)dbl2sll(rhs); return *this; }
+ inline Fix32 & operator-=(const int32_t rhs) { value -= int2sll(rhs); return *this; }
+
+ inline Fix32 & operator*=(const Fix32 &rhs) { value = sllmul(value, rhs.value); return *this; }
+ inline Fix32 & operator*=(const sll rhs) { value = sllmul(value, rhs); return *this; }
+ inline Fix32 & operator*=(const double rhs) { value = sllmul(value, dbl2sll(rhs)); return *this; }
+ inline Fix32 & operator*=(const float rhs) { value = sllmul(value, (float)dbl2sll(rhs)); return *this; }
+ inline Fix32 & operator*=(const int32_t rhs) { value *= rhs; return *this; }
+
+ inline Fix32 & operator/=(const Fix32 &rhs) { value = slldiv(value, rhs.value); return *this; }
+ inline Fix32 & operator/=(const sll rhs) { value = slldiv(value, rhs); return *this; }
+ inline Fix32 & operator/=(const double rhs) { value = slldiv(value, dbl2sll(rhs)); return *this; }
+ inline Fix32 & operator/=(const float rhs) { value = slldiv(value, (float)dbl2sll(rhs)); return *this; }
+ inline Fix32 & operator/=(const int32_t rhs) { value /= rhs; return *this; }
+
+ inline const Fix32 operator+(const Fix32 &other) const { Fix32 ret = *this; ret += other; return ret; }
+ inline const Fix32 operator+(const sll other) const { Fix32 ret = *this; ret += other; return ret; }
+ inline const Fix32 operator+(const double other) const { Fix32 ret = *this; ret += other; return ret; }
+ inline const Fix32 operator+(const float other) const { Fix32 ret = *this; ret += other; return ret; }
+ inline const Fix32 operator+(const int32_t other) const { Fix32 ret = *this; ret += other; return ret; }
+
+#ifndef FIXMATH_NO_OVERFLOW
+ inline const Fix32 sadd(const Fix32 &other) const { Fix32 ret = slladd(value, other.value); return ret; }
+ inline const Fix32 sadd(const sll other) const { Fix32 ret = slladd(value, other); return ret; }
+ inline const Fix32 sadd(const double other) const { Fix32 ret = slladd(value, dbl2sll(other)); return ret; }
+ inline const Fix32 sadd(const float other) const { Fix32 ret = slladd(value, (float)dbl2sll(other)); return ret; }
+ inline const Fix32 sadd(const int32_t other) const { Fix32 ret = slladd(value, int2sll(other)); return ret; }
+#endif
+
+ inline const Fix32 operator-(const Fix32 &other) const { Fix32 ret = *this; ret -= other; return ret; }
+ inline const Fix32 operator-(const sll other) const { Fix32 ret = *this; ret -= other; return ret; }
+ inline const Fix32 operator-(const double other) const { Fix32 ret = *this; ret -= other; return ret; }
+ inline const Fix32 operator-(const float other) const { Fix32 ret = *this; ret -= other; return ret; }
+ inline const Fix32 operator-(const int32_t other) const { Fix32 ret = *this; ret -= other; return ret; }
+
+ inline const Fix32 operator-() const { Fix32 ret = sllsub(0, value); return ret; }
+
+#ifndef FIXMATH_NO_OVERFLOW
+ inline const Fix32 ssub(const Fix32 &other) const { Fix32 ret = slladd(value, -other.value); return ret; }
+ inline const Fix32 ssub(const sll other) const { Fix32 ret = slladd(value, -other); return ret; }
+ inline const Fix32 ssub(const double other) const { Fix32 ret = slladd(value, -dbl2sll(other)); return ret; }
+ inline const Fix32 ssub(const float other) const { Fix32 ret = slladd(value, -(float)dbl2sll(other)); return ret; }
+ inline const Fix32 ssub(const int32_t other) const { Fix32 ret = slladd(value, -int2sll(other)); return ret; }
+#endif
+
+ inline const Fix32 operator*(const Fix32 &other) const { Fix32 ret = *this; ret *= other; return ret; }
+ inline const Fix32 operator*(const sll other) const { Fix32 ret = *this; ret *= other; return ret; }
+ inline const Fix32 operator*(const double other) const { Fix32 ret = *this; ret *= other; return ret; }
+ inline const Fix32 operator*(const float other) const { Fix32 ret = *this; ret *= other; return ret; }
+ inline const Fix32 operator*(const int32_t other) const { Fix32 ret = *this; ret *= other; return ret; }
+
+#ifndef FIXMATH_NO_OVERFLOW
+ inline const Fix32 smul(const Fix32 &other) const { Fix32 ret = sllmul(value, other.value); return ret; }
+ inline const Fix32 smul(const sll other) const { Fix32 ret = sllmul(value, other); return ret; }
+ inline const Fix32 smul(const double other) const { Fix32 ret = sllmul(value, dbl2sll(other)); return ret; }
+ inline const Fix32 smul(const float other) const { Fix32 ret = sllmul(value, (float)dbl2sll(other)); return ret; }
+ inline const Fix32 smul(const int32_t other) const { Fix32 ret = sllmul(value, int2sll(other)); return ret; }
+#endif
+
+ inline const Fix32 operator/(const Fix32 &other) const { Fix32 ret = *this; ret /= other; return ret; }
+ inline const Fix32 operator/(const sll other) const { Fix32 ret = *this; ret /= other; return ret; }
+ inline const Fix32 operator/(const double other) const { Fix32 ret = *this; ret /= other; return ret; }
+ inline const Fix32 operator/(const float other) const { Fix32 ret = *this; ret /= other; return ret; }
+ inline const Fix32 operator/(const int32_t other) const { Fix32 ret = *this; ret /= other; return ret; }
+
+#ifndef FIXMATH_NO_OVERFLOW
+ inline const Fix32 sdiv(const Fix32 &other) const { Fix32 ret = slldiv(value, other.value); return ret; }
+ inline const Fix32 sdiv(const sll other) const { Fix32 ret = slldiv(value, other); return ret; }
+ inline const Fix32 sdiv(const double other) const { Fix32 ret = slldiv(value, dbl2sll(other)); return ret; }
+ inline const Fix32 sdiv(const float other) const { Fix32 ret = slldiv(value, (float)dbl2sll(other)); return ret; }
+ inline const Fix32 sdiv(const int32_t other) const { Fix32 ret = slldiv(value, int2sll(other)); return ret; }
+#endif
+
+ inline int operator==(const Fix32 &other) const { return (value == other.value); }
+ inline int operator==(const sll other) const { return (value == other); }
+ inline int operator==(const double other) const { return (value == dbl2sll(other)); }
+ inline int operator==(const float other) const { return (value == (float)dbl2sll(other)); }
+ inline int operator==(const int32_t other) const { return (value == int2sll(other)); }
+
+ inline int operator!=(const Fix32 &other) const { return (value != other.value); }
+ inline int operator!=(const sll other) const { return (value != other); }
+ inline int operator!=(const double other) const { return (value != dbl2sll(other)); }
+ inline int operator!=(const float other) const { return (value != (float)dbl2sll(other)); }
+ inline int operator!=(const int32_t other) const { return (value != int2sll(other)); }
+
+ inline int operator<=(const Fix32 &other) const { return (value <= other.value); }
+ inline int operator<=(const sll other) const { return (value <= other); }
+ inline int operator<=(const double other) const { return (value <= dbl2sll(other)); }
+ inline int operator<=(const float other) const { return (value <= (float)dbl2sll(other)); }
+ inline int operator<=(const int32_t other) const { return (value <= int2sll(other)); }
+
+ inline int operator>=(const Fix32 &other) const { return (value >= other.value); }
+ inline int operator>=(const sll other) const { return (value >= other); }
+ inline int operator>=(const double other) const { return (value >= dbl2sll(other)); }
+ inline int operator>=(const float other) const { return (value >= (float)dbl2sll(other)); }
+ inline int operator>=(const int32_t other) const { return (value >= int2sll(other)); }
+
+ inline int operator< (const Fix32 &other) const { return (value < other.value); }
+ inline int operator< (const sll other) const { return (value < other); }
+ inline int operator< (const double other) const { return (value < dbl2sll(other)); }
+ inline int operator< (const float other) const { return (value < (float)dbl2sll(other)); }
+ inline int operator< (const int32_t other) const { return (value < int2sll(other)); }
+
+ inline int operator> (const Fix32 &other) const { return (value > other.value); }
+ inline int operator> (const sll other) const { return (value > other); }
+ inline int operator> (const double other) const { return (value > dbl2sll(other)); }
+ inline int operator> (const float other) const { return (value > (float)dbl2sll(other)); }
+ inline int operator> (const int32_t other) const { return (value > int2sll(other)); }
+
+ inline Fix32 sin() const { return Fix32(sllsin(value)); }
+ inline Fix32 cos() const { return Fix32(sllcos(value)); }
+ inline Fix32 tan() const { return Fix32(slltan(value)); }
+ inline Fix32 asin() const { return Fix32(sllasin(value)); }
+ inline Fix32 acos() const { return Fix32(sllacos(value)); }
+ inline Fix32 atan() const { return Fix32(sllatan(value)); }
+ //inline Fix32 atan2(const Fix32 &inY) const { return Fix32(fix16_atan2(value, inY.value)); }
+ inline Fix32 sqrt() const { return Fix32(sllsqrt(value)); }
+
+}; \ No newline at end of file