-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick.h
57 lines (47 loc) · 857 Bytes
/
quick.h
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
#pragma once
#include <cstdint>
class Quick
{
public:
void SetVal(int32_t v) { val = v; };
void SetInt(int32_t v) { val = v<<16; };
int32_t GetVal() { return val; };
int16_t GetInt() { return val >> 16; };
uint16_t GetFrac() { return val & 0xFFFF; };
Quick operator + (Quick const &obj)
{
Quick t;
t.val = val + obj.val;
return t;
}
Quick operator - (Quick const &obj)
{
Quick t;
t.val = val - obj.val;
return t;
}
Quick operator * (Quick const &obj)
{
Quick t;
int64_t t64 = obj.val;
t64 *= val;
t64 >>= 16;
t.val = static_cast<int32_t>(t64);
return t;
}
Quick operator / (Quick const &obj)
{
Quick t;
int64_t t64 = val;
t64 <<= 16;
t64 /= obj.val;
t.val = static_cast<int32_t>(t64);
return t;
}
bool operator < (Quick const &obj)
{
return val < obj.val;
}
private:
int32_t val;
};