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 typedef long fixed;
38 typedef int int4b;
39
40 enum {ROTATE, VECTOR};
41 typedef int fcordic;
42 enum {RAD, DEG};
43 typedef int tangle;
44
45 enum {
46 FRACTIONBITS = 17,
47 N = 17,
48 M = 9,
49 CORDIC_SCALE = 1 << FRACTIONBITS,
50 CORDIC_INTEGER = ~(CORDIC_SCALE - 1),
51 INT_SCALE = 1000,
52 };
53
54 #include "limits.h"
55
56 #define FIXED(X) (floatToFixed((X)))
57 #define FLOAT(X) ((X) / (double)CORDIC_SCALE)
58 #define INT2FIXED(X) (intToFixed((X), 0))
59 #define INT2FIXEDR(X) (intToFixed((X), 1))
60 #define FIXED2INT(X) (fixedToInt((X), 0))
61 #define FIXED2INTR(X) (fixedToInt((X), 1))
62
63
64
65 LUAI_DATA fixed FULL_CIRCLE[];
66 LUAI_DATA fixed HALF_CIRCLE[];
67 LUAI_DATA fixed QUART_CIRCLE[];
68
69 LUALIB_API fixed floatToFixed(double a);
70 LUALIB_API fixed intToFixed(int4b a, int round);
71 LUALIB_API int4b fixedToInt(fixed a, int round);
72
73 LUALIB_API fixed muldivScaled(fixed a, fixed b, fixed c);
74
75 LUALIB_API fixed sind(fixed phi);
76 LUALIB_API fixed cosd(fixed phi);
77 LUALIB_API fixed tand(fixed phi);
78 LUALIB_API void recd(fixed r, fixed theta, fixed *px, fixed *py);
79 LUALIB_API fixed asind(fixed x);
80 LUALIB_API fixed acosd(fixed x);
81 LUALIB_API fixed atand(fixed x);
82 LUALIB_API void pold(fixed px, fixed py, fixed *r, fixed *theta);
83
84 LUALIB_API fixed sinr(fixed phi);
85 LUALIB_API fixed cosr(fixed phi);
86 LUALIB_API fixed tanr(fixed phi);
87 LUALIB_API void recr(fixed r, fixed theta, fixed *px, fixed *py);
88 LUALIB_API fixed asinr(fixed x);
89 LUALIB_API fixed acosr(fixed x);
90 LUALIB_API fixed atanr(fixed x);
91 LUALIB_API void polr(fixed px, fixed py, fixed *r, fixed *theta);
92
93 LUALIB_API fixed fint(fixed a);
94 LUALIB_API fixed fceil(fixed a);
95 LUALIB_API fixed ffloor(fixed a);
96 LUALIB_API fixed fround(fixed a);