-
Notifications
You must be signed in to change notification settings - Fork 3
/
tableprinter.d
executable file
·106 lines (95 loc) · 1.35 KB
/
tableprinter.d
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
import std.stdio, std.math, std.conv, std.range, std.bitmanip;
enum MIN = 0, MAX = 20.0, VALS = 32;
alias fixed = int;
enum FIX_SHIFT = 10;
fixed toFixed(float f) {
return cast(fixed)(f * 2^^FIX_SHIFT);
}
float toFloat(fixed f) {
return ((f & ~((1 << FIX_SHIFT)-1))>>FIX_SHIFT) + (f & ((1 << FIX_SHIFT)-1)) / (2.0^^FIX_SHIFT);
}
void main(string[] args) {
int shiftAmount = 16;
if (args.length >= 2) args[1].to!int;
foreach (func; [&cos, &sin]) {
foreach (x; 0..VALS) {
auto angle = (MIN + x*(MAX-MIN)/(VALS-1.0));
auto fixedVal = func( angle *PI/180 ).toFixed;
writef("%04X", (cast(ushort) fixedVal).swapEndian);
//fixedVal.nativeToLittleEndian.each!(a => writefln("%02X", a));
//write(" (", fixedVal.toFloat, ")");
writeln;
//writefln("%d - 0x%08X - %f, %f", x, fixedVal, angle, func( angle *PI/180) );
}
writeln;
}
}
/*
current values (in little endian):
cos:
0004
FF03
FF03
FF03
FE03
FE03
FD03
FC03
FB03
FA03
F903
F803
F603
F503
F303
F103
EF03
ED03
EB03
E803
E603
E303
E003
DD03
DA03
D703
D403
D103
CD03
C903
C603
C203
sin:
0000
0B00
1700
2200
2E00
3900
4500
5000
5C00
6700
7300
7E00
8900
9500
A000
AC00
B700
C200
CE00
D900
E400
EF00
FB00
0601
1101
1C01
2701
3201
3D01
4801
5301
5E01
*/