-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixed32.cpp
More file actions
50 lines (42 loc) · 987 Bytes
/
Fixed32.cpp
File metadata and controls
50 lines (42 loc) · 987 Bytes
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
#include <cmath>
#include "Fixed32.hpp"
fixed32 fixed32::sin(int theta) {
if (!trigDataInitialized) {
initializeTrigData();
}
theta %= 360;
return sinData[theta];
}
fixed32 fixed32::cos(int theta) {
if (!trigDataInitialized) {
initializeTrigData();
}
theta += 90;
theta %= 360;
return sinData[theta];
}
fixed32 fixed32::tan(int theta) {
if (!trigDataInitialized) {
initializeTrigData();
}
theta %= 180;
return tanData[theta];
}
bool fixed32::trigDataInitialized = false;
void fixed32::initializeTrigData() {
initializeSin();
initializeTan();
trigDataInitialized = true;
}
fixed32 fixed32::sinData[360] = {};
fixed32 fixed32::tanData[180] = {};
void fixed32::initializeSin() {
for (int i = 0; i < 360; i++) {
sinData[i] = sinf(i * M_PI * 2 / 360.);
}
}
void fixed32::initializeTan() {
for (int i = 0; i < 180; i++) {
tanData[i] = tanf(i * M_PI * 2 / 360.);
}
}