aboutsummaryrefslogtreecommitdiff
path: root/Client/ThirdParty/fix32/fix32.hpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-03 11:38:15 +0800
committerchai <chaifix@163.com>2021-12-03 11:38:15 +0800
commite9ff46e5c8cc1646eb780e64d01be7b3430a628c (patch)
treedc77c642cc231d7d4e1432b6f4217e22ee509ef5 /Client/ThirdParty/fix32/fix32.hpp
parentb62f87c9496cb38f9c49139386edf85d4fa14390 (diff)
+PND_LIB
Diffstat (limited to 'Client/ThirdParty/fix32/fix32.hpp')
-rw-r--r--Client/ThirdParty/fix32/fix32.hpp176
1 files changed, 87 insertions, 89 deletions
diff --git a/Client/ThirdParty/fix32/fix32.hpp b/Client/ThirdParty/fix32/fix32.hpp
index e6945d8..e33f0fb 100644
--- a/Client/ThirdParty/fix32/fix32.hpp
+++ b/Client/ThirdParty/fix32/fix32.hpp
@@ -1,159 +1,157 @@
#pragma once
#include <stdint.h>
-extern "C" {
#include "math-sll/math-sll.h"
-}
// Q32.32
class Fix32
{
public:
- sll value; // signed long long
+ MathSLL::sll value; // signed long long
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 Fix32(const float inValue) { value = MathSLL::dbl2sll(inValue); }
+ inline Fix32(const double inValue) { value = MathSLL::dbl2sll(inValue); }
+ inline Fix32(const int32_t inValue) { value = MathSLL::int2sll(inValue); }
+ inline Fix32(const MathSLL::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 operator MathSLL::sll() const { return value; }
+ inline operator double() const { return MathSLL::sll2dbl(value); }
+ inline operator float() const { return (float)MathSLL::sll2dbl(value); }
+ inline operator int32_t() const { return (int32_t)MathSLL::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 MathSLL::sll rhs) { value = rhs; return *this; }
+ inline Fix32 & operator=(const double rhs) { value = MathSLL::dbl2sll(rhs); return *this; }
+ inline Fix32 & operator=(const float rhs) { value = (float)MathSLL::dbl2sll(rhs); return *this; }
+ inline Fix32 & operator=(const int32_t rhs) { value = MathSLL::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 MathSLL::sll rhs) { value += rhs; return *this; }
+ inline Fix32 & operator+=(const double rhs) { value += MathSLL::dbl2sll(rhs); return *this; }
+ inline Fix32 & operator+=(const float rhs) { value += (float)MathSLL::dbl2sll(rhs); return *this; }
+ inline Fix32 & operator+=(const int32_t rhs) { value += MathSLL::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 MathSLL::sll rhs) { value -= rhs; return *this; }
+ inline Fix32 & operator-=(const double rhs) { value -= MathSLL::dbl2sll(rhs); return *this; }
+ inline Fix32 & operator-=(const float rhs) { value -= (float)MathSLL::dbl2sll(rhs); return *this; }
+ inline Fix32 & operator-=(const int32_t rhs) { value -= MathSLL::int2sll(rhs); return *this; }
+
+ inline Fix32 & operator*=(const Fix32 &rhs) { value = MathSLL::sllmul(value, rhs.value); return *this; }
+ inline Fix32 & operator*=(const MathSLL::sll rhs) { value = MathSLL::sllmul(value, rhs); return *this; }
+ inline Fix32 & operator*=(const double rhs) { value = MathSLL::sllmul(value, MathSLL::dbl2sll(rhs)); return *this; }
+ inline Fix32 & operator*=(const float rhs) { value = MathSLL::sllmul(value, (float)MathSLL::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 Fix32 &rhs) { value = MathSLL::slldiv(value, rhs.value); return *this; }
+ inline Fix32 & operator/=(const MathSLL::sll rhs) { value = MathSLL::slldiv(value, rhs); return *this; }
+ inline Fix32 & operator/=(const double rhs) { value = MathSLL::slldiv(value, MathSLL::dbl2sll(rhs)); return *this; }
+ inline Fix32 & operator/=(const float rhs) { value = MathSLL::slldiv(value, (float)MathSLL::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 MathSLL::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; }
+ inline const Fix32 sadd(const Fix32 &other) const { Fix32 ret = MathSLL::slladd(value, other.value); return ret; }
+ inline const Fix32 sadd(const MathSLL::sll other) const { Fix32 ret = MathSLL::slladd(value, other); return ret; }
+ inline const Fix32 sadd(const double other) const { Fix32 ret = MathSLL::slladd(value, MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 sadd(const float other) const { Fix32 ret = MathSLL::slladd(value, (float)MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 sadd(const int32_t other) const { Fix32 ret = MathSLL::slladd(value, MathSLL::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 MathSLL::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; }
+ inline const Fix32 operator-() const { Fix32 ret = MathSLL::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; }
+ inline const Fix32 ssub(const Fix32 &other) const { Fix32 ret = MathSLL::slladd(value, -other.value); return ret; }
+ inline const Fix32 ssub(const MathSLL::sll other) const { Fix32 ret = MathSLL::slladd(value, -other); return ret; }
+ inline const Fix32 ssub(const double other) const { Fix32 ret = MathSLL::slladd(value, -MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 ssub(const float other) const { Fix32 ret = MathSLL::slladd(value, -(float)MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 ssub(const int32_t other) const { Fix32 ret = MathSLL::slladd(value, -MathSLL::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 MathSLL::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; }
+ inline const Fix32 smul(const Fix32 &other) const { Fix32 ret = MathSLL::sllmul(value, other.value); return ret; }
+ inline const Fix32 smul(const MathSLL::sll other) const { Fix32 ret = MathSLL::sllmul(value, other); return ret; }
+ inline const Fix32 smul(const double other) const { Fix32 ret = MathSLL::sllmul(value, MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 smul(const float other) const { Fix32 ret = MathSLL::sllmul(value, (float)MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 smul(const int32_t other) const { Fix32 ret = MathSLL::sllmul(value, MathSLL::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 MathSLL::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; }
+ inline const Fix32 sdiv(const Fix32 &other) const { Fix32 ret = MathSLL::slldiv(value, other.value); return ret; }
+ inline const Fix32 sdiv(const MathSLL::sll other) const { Fix32 ret = MathSLL::slldiv(value, other); return ret; }
+ inline const Fix32 sdiv(const double other) const { Fix32 ret = MathSLL::slldiv(value, MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 sdiv(const float other) const { Fix32 ret = MathSLL::slldiv(value, (float)MathSLL::dbl2sll(other)); return ret; }
+ inline const Fix32 sdiv(const int32_t other) const { Fix32 ret = MathSLL::slldiv(value, MathSLL::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 MathSLL::sll other) const { return (value == other); }
+ inline int operator==(const double other) const { return (value == MathSLL::dbl2sll(other)); }
+ inline int operator==(const float other) const { return (value == (float)MathSLL::dbl2sll(other)); }
+ inline int operator==(const int32_t other) const { return (value == MathSLL::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 MathSLL::sll other) const { return (value != other); }
+ inline int operator!=(const double other) const { return (value != MathSLL::dbl2sll(other)); }
+ inline int operator!=(const float other) const { return (value != (float)MathSLL::dbl2sll(other)); }
+ inline int operator!=(const int32_t other) const { return (value != MathSLL::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 MathSLL::sll other) const { return (value <= other); }
+ inline int operator<=(const double other) const { return (value <= MathSLL::dbl2sll(other)); }
+ inline int operator<=(const float other) const { return (value <= (float)MathSLL::dbl2sll(other)); }
+ inline int operator<=(const int32_t other) const { return (value <= MathSLL::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 MathSLL::sll other) const { return (value >= other); }
+ inline int operator>=(const double other) const { return (value >= MathSLL::dbl2sll(other)); }
+ inline int operator>=(const float other) const { return (value >= (float)MathSLL::dbl2sll(other)); }
+ inline int operator>=(const int32_t other) const { return (value >= MathSLL::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 MathSLL::sll other) const { return (value < other); }
+ inline int operator< (const double other) const { return (value < MathSLL::dbl2sll(other)); }
+ inline int operator< (const float other) const { return (value < (float)MathSLL::dbl2sll(other)); }
+ inline int operator< (const int32_t other) const { return (value < MathSLL::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 int operator> (const MathSLL::sll other) const { return (value > other); }
+ inline int operator> (const double other) const { return (value > MathSLL::dbl2sll(other)); }
+ inline int operator> (const float other) const { return (value > (float)MathSLL::dbl2sll(other)); }
+ inline int operator> (const int32_t other) const { return (value > MathSLL::int2sll(other)); }
+
+ inline Fix32 sin() const { return Fix32(MathSLL::sllsin(value)); }
+ inline Fix32 cos() const { return Fix32(MathSLL::sllcos(value)); }
+ inline Fix32 tan() const { return Fix32(MathSLL::slltan(value)); }
+ inline Fix32 asin() const { return Fix32(MathSLL::sllasin(value)); }
+ inline Fix32 acos() const { return Fix32(MathSLL::sllacos(value)); }
+ inline Fix32 atan() const { return Fix32(MathSLL::sllatan(value)); }
//inline Fix32 atan2(const Fix32 &inY) const { return Fix32(fix16_atan2(value, inY.value)); }
- inline Fix32 sqrt() const { return Fix32(sllsqrt(value)); }
+ inline Fix32 sqrt() const { return Fix32(MathSLL::sllsqrt(value)); }
}; \ No newline at end of file