7 f32 sinVal, cosVal, sinDt, cosDt;
17 {0.000000f, 1.000000f, 0.024541f, -0.000301f},
18 {0.024541f, 0.999699f, 0.024526f, -0.000903f},
19 {0.049068f, 0.998795f, 0.024497f, -0.001505f},
20 {0.073565f, 0.997290f, 0.024453f, -0.002106f},
21 {0.098017f, 0.995185f, 0.024394f, -0.002705f},
22 {0.122411f, 0.992480f, 0.024320f, -0.003303f},
23 {0.146730f, 0.989177f, 0.024231f, -0.003899f},
24 {0.170962f, 0.985278f, 0.024128f, -0.004492f},
25 {0.195090f, 0.980785f, 0.024011f, -0.005083f},
26 {0.219101f, 0.975702f, 0.023879f, -0.005671f},
27 {0.242980f, 0.970031f, 0.023733f, -0.006255f},
28 {0.266713f, 0.963776f, 0.023572f, -0.006836f},
29 {0.290285f, 0.956940f, 0.023397f, -0.007412f},
30 {0.313682f, 0.949528f, 0.023208f, -0.007984f},
31 {0.336890f, 0.941544f, 0.023005f, -0.008551f},
32 {0.359895f, 0.932993f, 0.022788f, -0.009113f},
33 {0.382683f, 0.923880f, 0.022558f, -0.009670f},
34 {0.405241f, 0.914210f, 0.022314f, -0.010220f},
35 {0.427555f, 0.903989f, 0.022056f, -0.010765f},
36 {0.449611f, 0.893224f, 0.021785f, -0.011303f},
37 {0.471397f, 0.881921f, 0.021501f, -0.011834f},
38 {0.492898f, 0.870087f, 0.021205f, -0.012358f},
39 {0.514103f, 0.857729f, 0.020895f, -0.012875f},
40 {0.534998f, 0.844854f, 0.020573f, -0.013384f},
41 {0.555570f, 0.831470f, 0.020238f, -0.013885f},
42 {0.575808f, 0.817585f, 0.019891f, -0.014377f},
43 {0.595699f, 0.803208f, 0.019532f, -0.014861f},
44 {0.615232f, 0.788346f, 0.019162f, -0.015336f},
45 {0.634393f, 0.773010f, 0.018780f, -0.015802f},
46 {0.653173f, 0.757209f, 0.018386f, -0.016258f},
47 {0.671559f, 0.740951f, 0.017982f, -0.016704f},
48 {0.689541f, 0.724247f, 0.017566f, -0.017140f},
49 {0.707107f, 0.707107f, 0.017140f, -0.017566f},
50 {0.724247f, 0.689541f, 0.016704f, -0.017982f},
51 {0.740951f, 0.671559f, 0.016258f, -0.018386f},
52 {0.757209f, 0.653173f, 0.015802f, -0.018780f},
53 {0.773010f, 0.634393f, 0.015336f, -0.019162f},
54 {0.788346f, 0.615232f, 0.014861f, -0.019532f},
55 {0.803208f, 0.595699f, 0.014377f, -0.019891f},
56 {0.817585f, 0.575808f, 0.013885f, -0.020238f},
57 {0.831470f, 0.555570f, 0.013384f, -0.020573f},
58 {0.844854f, 0.534998f, 0.012875f, -0.020895f},
59 {0.857729f, 0.514103f, 0.012358f, -0.021205f},
60 {0.870087f, 0.492898f, 0.011834f, -0.021501f},
61 {0.881921f, 0.471397f, 0.011303f, -0.021785f},
62 {0.893224f, 0.449611f, 0.010765f, -0.022056f},
63 {0.903989f, 0.427555f, 0.010220f, -0.022314f},
64 {0.914210f, 0.405241f, 0.009670f, -0.022558f},
65 {0.923880f, 0.382683f, 0.009113f, -0.022788f},
66 {0.932993f, 0.359895f, 0.008551f, -0.023005f},
67 {0.941544f, 0.336890f, 0.007984f, -0.023208f},
68 {0.949528f, 0.313682f, 0.007412f, -0.023397f},
69 {0.956940f, 0.290285f, 0.006836f, -0.023572f},
70 {0.963776f, 0.266713f, 0.006255f, -0.023733f},
71 {0.970031f, 0.242980f, 0.005671f, -0.023879f},
72 {0.975702f, 0.219101f, 0.005083f, -0.024011f},
73 {0.980785f, 0.195090f, 0.004492f, -0.024128f},
74 {0.985278f, 0.170962f, 0.003899f, -0.024231f},
75 {0.989177f, 0.146730f, 0.003303f, -0.024320f},
76 {0.992480f, 0.122411f, 0.002705f, -0.024394f},
77 {0.995185f, 0.098017f, 0.002106f, -0.024453f},
78 {0.997290f, 0.073565f, 0.001505f, -0.024497f},
79 {0.998795f, 0.049068f, 0.000903f, -0.024526f},
80 {0.999699f, 0.024541f, 0.000301f, -0.024541f},
81 {1.000000f, 0.000000f, -0.000301f, -0.024541f},
82 {0.999699f, -0.024541f, -0.000903f, -0.024526f},
83 {0.998795f, -0.049068f, -0.001505f, -0.024497f},
84 {0.997290f, -0.073565f, -0.002106f, -0.024453f},
85 {0.995185f, -0.098017f, -0.002705f, -0.024394f},
86 {0.992480f, -0.122411f, -0.003303f, -0.024320f},
87 {0.989177f, -0.146730f, -0.003899f, -0.024231f},
88 {0.985278f, -0.170962f, -0.004492f, -0.024128f},
89 {0.980785f, -0.195090f, -0.005083f, -0.024011f},
90 {0.975702f, -0.219101f, -0.005671f, -0.023879f},
91 {0.970031f, -0.242980f, -0.006255f, -0.023733f},
92 {0.963776f, -0.266713f, -0.006836f, -0.023572f},
93 {0.956940f, -0.290285f, -0.007412f, -0.023397f},
94 {0.949528f, -0.313682f, -0.007984f, -0.023208f},
95 {0.941544f, -0.336890f, -0.008551f, -0.023005f},
96 {0.932993f, -0.359895f, -0.009113f, -0.022788f},
97 {0.923880f, -0.382683f, -0.009670f, -0.022558f},
98 {0.914210f, -0.405241f, -0.010220f, -0.022314f},
99 {0.903989f, -0.427555f, -0.010765f, -0.022056f},
100 {0.893224f, -0.449611f, -0.011303f, -0.021785f},
101 {0.881921f, -0.471397f, -0.011834f, -0.021501f},
102 {0.870087f, -0.492898f, -0.012358f, -0.021205f},
103 {0.857729f, -0.514103f, -0.012875f, -0.020895f},
104 {0.844854f, -0.534998f, -0.013384f, -0.020573f},
105 {0.831470f, -0.555570f, -0.013885f, -0.020238f},
106 {0.817585f, -0.575808f, -0.014377f, -0.019891f},
107 {0.803208f, -0.595699f, -0.014861f, -0.019532f},
108 {0.788346f, -0.615232f, -0.015336f, -0.019162f},
109 {0.773010f, -0.634393f, -0.015802f, -0.018780f},
110 {0.757209f, -0.653173f, -0.016258f, -0.018386f},
111 {0.740951f, -0.671559f, -0.016704f, -0.017982f},
112 {0.724247f, -0.689541f, -0.017140f, -0.017566f},
113 {0.707107f, -0.707107f, -0.017566f, -0.017140f},
114 {0.689541f, -0.724247f, -0.017982f, -0.016704f},
115 {0.671559f, -0.740951f, -0.018386f, -0.016258f},
116 {0.653173f, -0.757209f, -0.018780f, -0.015802f},
117 {0.634393f, -0.773010f, -0.019162f, -0.015336f},
118 {0.615232f, -0.788346f, -0.019532f, -0.014861f},
119 {0.595699f, -0.803208f, -0.019891f, -0.014377f},
120 {0.575808f, -0.817585f, -0.020238f, -0.013885f},
121 {0.555570f, -0.831470f, -0.020573f, -0.013384f},
122 {0.534998f, -0.844854f, -0.020895f, -0.012875f},
123 {0.514103f, -0.857729f, -0.021205f, -0.012358f},
124 {0.492898f, -0.870087f, -0.021501f, -0.011834f},
125 {0.471397f, -0.881921f, -0.021785f, -0.011303f},
126 {0.449611f, -0.893224f, -0.022056f, -0.010765f},
127 {0.427555f, -0.903989f, -0.022314f, -0.010220f},
128 {0.405241f, -0.914210f, -0.022558f, -0.009670f},
129 {0.382683f, -0.923880f, -0.022788f, -0.009113f},
130 {0.359895f, -0.932993f, -0.023005f, -0.008551f},
131 {0.336890f, -0.941544f, -0.023208f, -0.007984f},
132 {0.313682f, -0.949528f, -0.023397f, -0.007412f},
133 {0.290285f, -0.956940f, -0.023572f, -0.006836f},
134 {0.266713f, -0.963776f, -0.023733f, -0.006255f},
135 {0.242980f, -0.970031f, -0.023879f, -0.005671f},
136 {0.219101f, -0.975702f, -0.024011f, -0.005083f},
137 {0.195090f, -0.980785f, -0.024128f, -0.004492f},
138 {0.170962f, -0.985278f, -0.024231f, -0.003899f},
139 {0.146730f, -0.989177f, -0.024320f, -0.003303f},
140 {0.122411f, -0.992480f, -0.024394f, -0.002705f},
141 {0.098017f, -0.995185f, -0.024453f, -0.002106f},
142 {0.073565f, -0.997290f, -0.024497f, -0.001505f},
143 {0.049068f, -0.998795f, -0.024526f, -0.000903f},
144 {0.024541f, -0.999699f, -0.024541f, -0.000301f},
145 {0.000000f, -1.000000f, -0.024541f, 0.000301f},
146 {-0.024541f, -0.999699f, -0.024526f, 0.000903f},
147 {-0.049068f, -0.998795f, -0.024497f, 0.001505f},
148 {-0.073565f, -0.997290f, -0.024453f, 0.002106f},
149 {-0.098017f, -0.995185f, -0.024394f, 0.002705f},
150 {-0.122411f, -0.992480f, -0.024320f, 0.003303f},
151 {-0.146730f, -0.989177f, -0.024231f, 0.003899f},
152 {-0.170962f, -0.985278f, -0.024128f, 0.004492f},
153 {-0.195090f, -0.980785f, -0.024011f, 0.005083f},
154 {-0.219101f, -0.975702f, -0.023879f, 0.005671f},
155 {-0.242980f, -0.970031f, -0.023733f, 0.006255f},
156 {-0.266713f, -0.963776f, -0.023572f, 0.006836f},
157 {-0.290285f, -0.956940f, -0.023397f, 0.007412f},
158 {-0.313682f, -0.949528f, -0.023208f, 0.007984f},
159 {-0.336890f, -0.941544f, -0.023005f, 0.008551f},
160 {-0.359895f, -0.932993f, -0.022788f, 0.009113f},
161 {-0.382683f, -0.923880f, -0.022558f, 0.009670f},
162 {-0.405241f, -0.914210f, -0.022314f, 0.010220f},
163 {-0.427555f, -0.903989f, -0.022056f, 0.010765f},
164 {-0.449611f, -0.893224f, -0.021785f, 0.011303f},
165 {-0.471397f, -0.881921f, -0.021501f, 0.011834f},
166 {-0.492898f, -0.870087f, -0.021205f, 0.012358f},
167 {-0.514103f, -0.857729f, -0.020895f, 0.012875f},
168 {-0.534998f, -0.844854f, -0.020573f, 0.013384f},
169 {-0.555570f, -0.831470f, -0.020238f, 0.013885f},
170 {-0.575808f, -0.817585f, -0.019891f, 0.014377f},
171 {-0.595699f, -0.803208f, -0.019532f, 0.014861f},
172 {-0.615232f, -0.788346f, -0.019162f, 0.015336f},
173 {-0.634393f, -0.773010f, -0.018780f, 0.015802f},
174 {-0.653173f, -0.757209f, -0.018386f, 0.016258f},
175 {-0.671559f, -0.740951f, -0.017982f, 0.016704f},
176 {-0.689541f, -0.724247f, -0.017566f, 0.017140f},
177 {-0.707107f, -0.707107f, -0.017140f, 0.017566f},
178 {-0.724247f, -0.689541f, -0.016704f, 0.017982f},
179 {-0.740951f, -0.671559f, -0.016258f, 0.018386f},
180 {-0.757209f, -0.653173f, -0.015802f, 0.018780f},
181 {-0.773010f, -0.634393f, -0.015336f, 0.019162f},
182 {-0.788346f, -0.615232f, -0.014861f, 0.019532f},
183 {-0.803208f, -0.595699f, -0.014377f, 0.019891f},
184 {-0.817585f, -0.575808f, -0.013885f, 0.020238f},
185 {-0.831470f, -0.555570f, -0.013384f, 0.020573f},
186 {-0.844854f, -0.534998f, -0.012875f, 0.020895f},
187 {-0.857729f, -0.514103f, -0.012358f, 0.021205f},
188 {-0.870087f, -0.492898f, -0.011834f, 0.021501f},
189 {-0.881921f, -0.471397f, -0.011303f, 0.021785f},
190 {-0.893224f, -0.449611f, -0.010765f, 0.022056f},
191 {-0.903989f, -0.427555f, -0.010220f, 0.022314f},
192 {-0.914210f, -0.405241f, -0.009670f, 0.022558f},
193 {-0.923880f, -0.382683f, -0.009113f, 0.022788f},
194 {-0.932993f, -0.359895f, -0.008551f, 0.023005f},
195 {-0.941544f, -0.336890f, -0.007984f, 0.023208f},
196 {-0.949528f, -0.313682f, -0.007412f, 0.023397f},
197 {-0.956940f, -0.290285f, -0.006836f, 0.023572f},
198 {-0.963776f, -0.266713f, -0.006255f, 0.023733f},
199 {-0.970031f, -0.242980f, -0.005671f, 0.023879f},
200 {-0.975702f, -0.219101f, -0.005083f, 0.024011f},
201 {-0.980785f, -0.195090f, -0.004492f, 0.024128f},
202 {-0.985278f, -0.170962f, -0.003899f, 0.024231f},
203 {-0.989177f, -0.146730f, -0.003303f, 0.024320f},
204 {-0.992480f, -0.122411f, -0.002705f, 0.024394f},
205 {-0.995185f, -0.098017f, -0.002106f, 0.024453f},
206 {-0.997290f, -0.073565f, -0.001505f, 0.024497f},
207 {-0.998795f, -0.049068f, -0.000903f, 0.024526f},
208 {-0.999699f, -0.024541f, -0.000301f, 0.024541f},
209 {-1.000000f, -0.000000f, 0.000301f, 0.024541f},
210 {-0.999699f, 0.024541f, 0.000903f, 0.024526f},
211 {-0.998795f, 0.049068f, 0.001505f, 0.024497f},
212 {-0.997290f, 0.073565f, 0.002106f, 0.024453f},
213 {-0.995185f, 0.098017f, 0.002705f, 0.024394f},
214 {-0.992480f, 0.122411f, 0.003303f, 0.024320f},
215 {-0.989177f, 0.146730f, 0.003899f, 0.024231f},
216 {-0.985278f, 0.170962f, 0.004492f, 0.024128f},
217 {-0.980785f, 0.195090f, 0.005083f, 0.024011f},
218 {-0.975702f, 0.219101f, 0.005671f, 0.023879f},
219 {-0.970031f, 0.242980f, 0.006255f, 0.023733f},
220 {-0.963776f, 0.266713f, 0.006836f, 0.023572f},
221 {-0.956940f, 0.290285f, 0.007412f, 0.023397f},
222 {-0.949528f, 0.313682f, 0.007984f, 0.023208f},
223 {-0.941544f, 0.336890f, 0.008551f, 0.023005f},
224 {-0.932993f, 0.359895f, 0.009113f, 0.022788f},
225 {-0.923880f, 0.382683f, 0.009670f, 0.022558f},
226 {-0.914210f, 0.405241f, 0.010220f, 0.022314f},
227 {-0.903989f, 0.427555f, 0.010765f, 0.022056f},
228 {-0.893224f, 0.449611f, 0.011303f, 0.021785f},
229 {-0.881921f, 0.471397f, 0.011834f, 0.021501f},
230 {-0.870087f, 0.492898f, 0.012358f, 0.021205f},
231 {-0.857729f, 0.514103f, 0.012875f, 0.020895f},
232 {-0.844854f, 0.534998f, 0.013384f, 0.020573f},
233 {-0.831470f, 0.555570f, 0.013885f, 0.020238f},
234 {-0.817585f, 0.575808f, 0.014377f, 0.019891f},
235 {-0.803208f, 0.595699f, 0.014861f, 0.019532f},
236 {-0.788346f, 0.615232f, 0.015336f, 0.019162f},
237 {-0.773010f, 0.634393f, 0.015802f, 0.018780f},
238 {-0.757209f, 0.653173f, 0.016258f, 0.018386f},
239 {-0.740951f, 0.671559f, 0.016704f, 0.017982f},
240 {-0.724247f, 0.689541f, 0.017140f, 0.017566f},
241 {-0.707107f, 0.707107f, 0.017566f, 0.017140f},
242 {-0.689541f, 0.724247f, 0.017982f, 0.016704f},
243 {-0.671559f, 0.740951f, 0.018386f, 0.016258f},
244 {-0.653173f, 0.757209f, 0.018780f, 0.015802f},
245 {-0.634393f, 0.773010f, 0.019162f, 0.015336f},
246 {-0.615232f, 0.788346f, 0.019532f, 0.014861f},
247 {-0.595699f, 0.803208f, 0.019891f, 0.014377f},
248 {-0.575808f, 0.817585f, 0.020238f, 0.013885f},
249 {-0.555570f, 0.831470f, 0.020573f, 0.013384f},
250 {-0.534998f, 0.844854f, 0.020895f, 0.012875f},
251 {-0.514103f, 0.857729f, 0.021205f, 0.012358f},
252 {-0.492898f, 0.870087f, 0.021501f, 0.011834f},
253 {-0.471397f, 0.881921f, 0.021785f, 0.011303f},
254 {-0.449611f, 0.893224f, 0.022056f, 0.010765f},
255 {-0.427555f, 0.903989f, 0.022314f, 0.010220f},
256 {-0.405241f, 0.914210f, 0.022558f, 0.009670f},
257 {-0.382683f, 0.923880f, 0.022788f, 0.009113f},
258 {-0.359895f, 0.932993f, 0.023005f, 0.008551f},
259 {-0.336890f, 0.941544f, 0.023208f, 0.007984f},
260 {-0.313682f, 0.949528f, 0.023397f, 0.007412f},
261 {-0.290285f, 0.956940f, 0.023572f, 0.006836f},
262 {-0.266713f, 0.963776f, 0.023733f, 0.006255f},
263 {-0.242980f, 0.970031f, 0.023879f, 0.005671f},
264 {-0.219101f, 0.975702f, 0.024011f, 0.005083f},
265 {-0.195090f, 0.980785f, 0.024128f, 0.004492f},
266 {-0.170962f, 0.985278f, 0.024231f, 0.003899f},
267 {-0.146730f, 0.989177f, 0.024320f, 0.003303f},
268 {-0.122411f, 0.992480f, 0.024394f, 0.002705f},
269 {-0.098017f, 0.995185f, 0.024453f, 0.002106f},
270 {-0.073565f, 0.997290f, 0.024497f, 0.001505f},
271 {-0.049068f, 0.998795f, 0.024526f, 0.000903f},
272 {-0.024541f, 0.999699f, 0.024541f, 0.000301f},
273 {-0.000000f, 1.000000f, 0.024541f, -0.000301f},
277static constexpr AtanEntry sArcTanTbl[32 + 1] = {
278 {0.000000000f, 1.272825321f},
279 {1.272825321f, 1.270345790f},
280 {2.543171111f, 1.265415586f},
281 {3.808586697f, 1.258091595f},
282 {5.066678293f, 1.248457103f},
283 {6.315135396f, 1.236619467f},
284 {7.551754863f, 1.222707202f},
285 {8.774462065f, 1.206866624f},
286 {9.981328688f, 1.189258212f},
287 {11.170586901f, 1.170052841f},
288 {12.340639741f, 1.149428034f},
289 {13.490067775f, 1.127564381f},
290 {14.617632156f, 1.104642222f},
291 {15.722274378f, 1.080838675f},
292 {16.803113053f, 1.056325088f},
293 {17.859438141f, 1.031264918f},
294 {18.890703059f, 1.005812061f},
295 {19.896515121f, 0.980109621f},
296 {20.876624742f, 0.954289072f},
297 {21.830913814f, 0.928469801f},
298 {22.759383615f, 0.902758952f},
299 {23.662142567f, 0.877251558f},
300 {24.539394125f, 0.852030871f},
301 {25.391424996f, 0.827168886f},
302 {26.218593881f, 0.802726967f},
303 {27.021320848f, 0.778756582f},
304 {27.800077430f, 0.755300081f},
305 {28.555377511f, 0.732391496f},
306 {29.287769007f, 0.710057351f},
307 {29.997826358f, 0.688317453f},
308 {30.686143811f, 0.667185647f},
309 {31.353329458f, 0.646670542f},
310 {32.000000000f, 0.626776175f},
317 f64 est = frsqrte(x);
320 f32 tmp0 =
static_cast<f32
>(est *
force25Bit(est));
321 f32 tmp1 =
static_cast<f32
>(est *
static_cast<f64
>(0.5f));
323 static_cast<f32
>(
static_cast<f64
>(3.0f) -
static_cast<f64
>(tmp0) *
static_cast<f64
>(x));
328f32 SinFIdx(f32 fidx) {
329 f32 abs_fidx = fabs(fidx);
331 while (abs_fidx >= 65536.0f) {
332 abs_fidx -= 65536.0f;
335 u16 idx =
static_cast<u16>(abs_fidx);
336 f32 r = abs_fidx -
static_cast<f32
>(idx);
338 f32 val = sSinCosTbl[idx].sinVal + r * sSinCosTbl[idx].sinDt;
339 return fidx < 0.0f ? -val : val;
343f32 CosFIdx(f32 fidx) {
344 f32 abs_fidx = fabs(fidx);
346 while (abs_fidx >= 65536.0f) {
347 abs_fidx -= 65536.0f;
350 u16 idx =
static_cast<u16>(abs_fidx);
351 f32 r = abs_fidx -
static_cast<f32
>(idx);
354 return sSinCosTbl[idx].cosVal + r * sSinCosTbl[idx].cosDt;
357f32 AtanFIdx_(f32 x) {
359 u16 idx =
static_cast<u16>(x);
360 f32 r = x -
static_cast<f32
>(idx);
361 return sArcTanTbl[idx].atanVal + r * sArcTanTbl[idx].atanDt;
365f32 Atan2FIdx(f32 y, f32 x) {
366 if (x == 0.0f && y == 0.0f) {
373 return 0.0f + AtanFIdx_(y / x);
375 return 64.0f - AtanFIdx_(x / y);
379 return 0.0f - AtanFIdx_(-y / x);
381 return -64.0f + AtanFIdx_(x / -y);
387 return 128.0f - AtanFIdx_(y / -x);
389 return 64.0f + AtanFIdx_(-x / y);
393 return -128.0f + AtanFIdx_(-y / -x);
395 return -64.0f - AtanFIdx_(-x / -y);