1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#pragma once
#include <stdint.h>
extern "C" {
#include "math-sll/math-sll.h"
}
// Q32.32
class Fix32
{
public:
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 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)); }
};
|