Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
3 | * It is copyright by its individual contributors, as recorded in the |
||
4 | * project's Git history. See COPYING.txt at the top level for license |
||
5 | * terms and a link to the Git history. |
||
6 | */ |
||
7 | |||
8 | /* |
||
9 | * |
||
10 | * C version of fixed point library |
||
11 | * |
||
12 | */ |
||
13 | |||
14 | #include "maths.h" |
||
15 | |||
16 | namespace dcx { |
||
17 | |||
18 | const std::array<ubyte, 256> guess_table{{ |
||
19 | 1, |
||
20 | 1,1,1, |
||
21 | 2,2,2,2,2, |
||
22 | 3,3,3,3,3,3,3, |
||
23 | 4,4,4,4,4,4,4,4,4, |
||
24 | 5,5,5,5,5,5,5,5,5,5,5, |
||
25 | 6,6,6,6,6,6,6,6,6,6,6,6,6, |
||
26 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
||
27 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
||
28 | 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, |
||
29 | 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, |
||
30 | 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, |
||
31 | 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, |
||
32 | 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, |
||
33 | 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, |
||
34 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 |
||
35 | }}; |
||
36 | |||
37 | const std::array<int16_t, 256> sincos_table{{ |
||
38 | 0, |
||
39 | 402, |
||
40 | 804, |
||
41 | 1205, |
||
42 | 1606, |
||
43 | 2006, |
||
44 | 2404, |
||
45 | 2801, |
||
46 | 3196, |
||
47 | 3590, |
||
48 | 3981, |
||
49 | 4370, |
||
50 | 4756, |
||
51 | 5139, |
||
52 | 5520, |
||
53 | 5897, |
||
54 | 6270, |
||
55 | 6639, |
||
56 | 7005, |
||
57 | 7366, |
||
58 | 7723, |
||
59 | 8076, |
||
60 | 8423, |
||
61 | 8765, |
||
62 | 9102, |
||
63 | 9434, |
||
64 | 9760, |
||
65 | 10080, |
||
66 | 10394, |
||
67 | 10702, |
||
68 | 11003, |
||
69 | 11297, |
||
70 | 11585, |
||
71 | 11866, |
||
72 | 12140, |
||
73 | 12406, |
||
74 | 12665, |
||
75 | 12916, |
||
76 | 13160, |
||
77 | 13395, |
||
78 | 13623, |
||
79 | 13842, |
||
80 | 14053, |
||
81 | 14256, |
||
82 | 14449, |
||
83 | 14635, |
||
84 | 14811, |
||
85 | 14978, |
||
86 | 15137, |
||
87 | 15286, |
||
88 | 15426, |
||
89 | 15557, |
||
90 | 15679, |
||
91 | 15791, |
||
92 | 15893, |
||
93 | 15986, |
||
94 | 16069, |
||
95 | 16143, |
||
96 | 16207, |
||
97 | 16261, |
||
98 | 16305, |
||
99 | 16340, |
||
100 | 16364, |
||
101 | 16379, |
||
102 | // cos_table |
||
103 | 16384, |
||
104 | 16379, |
||
105 | 16364, |
||
106 | 16340, |
||
107 | 16305, |
||
108 | 16261, |
||
109 | 16207, |
||
110 | 16143, |
||
111 | 16069, |
||
112 | 15986, |
||
113 | 15893, |
||
114 | 15791, |
||
115 | 15679, |
||
116 | 15557, |
||
117 | 15426, |
||
118 | 15286, |
||
119 | 15137, |
||
120 | 14978, |
||
121 | 14811, |
||
122 | 14635, |
||
123 | 14449, |
||
124 | 14256, |
||
125 | 14053, |
||
126 | 13842, |
||
127 | 13623, |
||
128 | 13395, |
||
129 | 13160, |
||
130 | 12916, |
||
131 | 12665, |
||
132 | 12406, |
||
133 | 12140, |
||
134 | 11866, |
||
135 | 11585, |
||
136 | 11297, |
||
137 | 11003, |
||
138 | 10702, |
||
139 | 10394, |
||
140 | 10080, |
||
141 | 9760, |
||
142 | 9434, |
||
143 | 9102, |
||
144 | 8765, |
||
145 | 8423, |
||
146 | 8076, |
||
147 | 7723, |
||
148 | 7366, |
||
149 | 7005, |
||
150 | 6639, |
||
151 | 6270, |
||
152 | 5897, |
||
153 | 5520, |
||
154 | 5139, |
||
155 | 4756, |
||
156 | 4370, |
||
157 | 3981, |
||
158 | 3590, |
||
159 | 3196, |
||
160 | 2801, |
||
161 | 2404, |
||
162 | 2006, |
||
163 | 1606, |
||
164 | 1205, |
||
165 | 804, |
||
166 | 402, |
||
167 | 0, |
||
168 | -402, |
||
169 | -804, |
||
170 | -1205, |
||
171 | -1606, |
||
172 | -2006, |
||
173 | -2404, |
||
174 | -2801, |
||
175 | -3196, |
||
176 | -3590, |
||
177 | -3981, |
||
178 | -4370, |
||
179 | -4756, |
||
180 | -5139, |
||
181 | -5520, |
||
182 | -5897, |
||
183 | -6270, |
||
184 | -6639, |
||
185 | -7005, |
||
186 | -7366, |
||
187 | -7723, |
||
188 | -8076, |
||
189 | -8423, |
||
190 | -8765, |
||
191 | -9102, |
||
192 | -9434, |
||
193 | -9760, |
||
194 | -10080, |
||
195 | -10394, |
||
196 | -10702, |
||
197 | -11003, |
||
198 | -11297, |
||
199 | -11585, |
||
200 | -11866, |
||
201 | -12140, |
||
202 | -12406, |
||
203 | -12665, |
||
204 | -12916, |
||
205 | -13160, |
||
206 | -13395, |
||
207 | -13623, |
||
208 | -13842, |
||
209 | -14053, |
||
210 | -14256, |
||
211 | -14449, |
||
212 | -14635, |
||
213 | -14811, |
||
214 | -14978, |
||
215 | -15137, |
||
216 | -15286, |
||
217 | -15426, |
||
218 | -15557, |
||
219 | -15679, |
||
220 | -15791, |
||
221 | -15893, |
||
222 | -15986, |
||
223 | -16069, |
||
224 | -16143, |
||
225 | -16207, |
||
226 | -16261, |
||
227 | -16305, |
||
228 | -16340, |
||
229 | -16364, |
||
230 | -16379, |
||
231 | -16384, |
||
232 | -16379, |
||
233 | -16364, |
||
234 | -16340, |
||
235 | -16305, |
||
236 | -16261, |
||
237 | -16207, |
||
238 | -16143, |
||
239 | -16069, |
||
240 | -15986, |
||
241 | -15893, |
||
242 | -15791, |
||
243 | -15679, |
||
244 | -15557, |
||
245 | -15426, |
||
246 | -15286, |
||
247 | -15137, |
||
248 | -14978, |
||
249 | -14811, |
||
250 | -14635, |
||
251 | -14449, |
||
252 | -14256, |
||
253 | -14053, |
||
254 | -13842, |
||
255 | -13623, |
||
256 | -13395, |
||
257 | -13160, |
||
258 | -12916, |
||
259 | -12665, |
||
260 | -12406, |
||
261 | -12140, |
||
262 | -11866, |
||
263 | -11585, |
||
264 | -11297, |
||
265 | -11003, |
||
266 | -10702, |
||
267 | -10394, |
||
268 | -10080, |
||
269 | -9760, |
||
270 | -9434, |
||
271 | -9102, |
||
272 | -8765, |
||
273 | -8423, |
||
274 | -8076, |
||
275 | -7723, |
||
276 | -7366, |
||
277 | -7005, |
||
278 | -6639, |
||
279 | -6270, |
||
280 | -5897, |
||
281 | -5520, |
||
282 | -5139, |
||
283 | -4756, |
||
284 | -4370, |
||
285 | -3981, |
||
286 | -3590, |
||
287 | -3196, |
||
288 | -2801, |
||
289 | -2404, |
||
290 | -2006, |
||
291 | -1606, |
||
292 | -1205, |
||
293 | -804, |
||
294 | -402, |
||
295 | }}; |
||
296 | |||
297 | const std::array<ushort, 258> asin_table{{ |
||
298 | 0, |
||
299 | 41, |
||
300 | 81, |
||
301 | 122, |
||
302 | 163, |
||
303 | 204, |
||
304 | 244, |
||
305 | 285, |
||
306 | 326, |
||
307 | 367, |
||
308 | 408, |
||
309 | 448, |
||
310 | 489, |
||
311 | 530, |
||
312 | 571, |
||
313 | 612, |
||
314 | 652, |
||
315 | 693, |
||
316 | 734, |
||
317 | 775, |
||
318 | 816, |
||
319 | 857, |
||
320 | 897, |
||
321 | 938, |
||
322 | 979, |
||
323 | 1020, |
||
324 | 1061, |
||
325 | 1102, |
||
326 | 1143, |
||
327 | 1184, |
||
328 | 1225, |
||
329 | 1266, |
||
330 | 1307, |
||
331 | 1348, |
||
332 | 1389, |
||
333 | 1431, |
||
334 | 1472, |
||
335 | 1513, |
||
336 | 1554, |
||
337 | 1595, |
||
338 | 1636, |
||
339 | 1678, |
||
340 | 1719, |
||
341 | 1760, |
||
342 | 1802, |
||
343 | 1843, |
||
344 | 1884, |
||
345 | 1926, |
||
346 | 1967, |
||
347 | 2009, |
||
348 | 2050, |
||
349 | 2092, |
||
350 | 2134, |
||
351 | 2175, |
||
352 | 2217, |
||
353 | 2259, |
||
354 | 2300, |
||
355 | 2342, |
||
356 | 2384, |
||
357 | 2426, |
||
358 | 2468, |
||
359 | 2510, |
||
360 | 2551, |
||
361 | 2593, |
||
362 | 2636, |
||
363 | 2678, |
||
364 | 2720, |
||
365 | 2762, |
||
366 | 2804, |
||
367 | 2847, |
||
368 | 2889, |
||
369 | 2931, |
||
370 | 2974, |
||
371 | 3016, |
||
372 | 3059, |
||
373 | 3101, |
||
374 | 3144, |
||
375 | 3187, |
||
376 | 3229, |
||
377 | 3272, |
||
378 | 3315, |
||
379 | 3358, |
||
380 | 3401, |
||
381 | 3444, |
||
382 | 3487, |
||
383 | 3530, |
||
384 | 3573, |
||
385 | 3617, |
||
386 | 3660, |
||
387 | 3704, |
||
388 | 3747, |
||
389 | 3791, |
||
390 | 3834, |
||
391 | 3878, |
||
392 | 3922, |
||
393 | 3965, |
||
394 | 4009, |
||
395 | 4053, |
||
396 | 4097, |
||
397 | 4142, |
||
398 | 4186, |
||
399 | 4230, |
||
400 | 4275, |
||
401 | 4319, |
||
402 | 4364, |
||
403 | 4408, |
||
404 | 4453, |
||
405 | 4498, |
||
406 | 4543, |
||
407 | 4588, |
||
408 | 4633, |
||
409 | 4678, |
||
410 | 4723, |
||
411 | 4768, |
||
412 | 4814, |
||
413 | 4859, |
||
414 | 4905, |
||
415 | 4951, |
||
416 | 4997, |
||
417 | 5043, |
||
418 | 5089, |
||
419 | 5135, |
||
420 | 5181, |
||
421 | 5228, |
||
422 | 5274, |
||
423 | 5321, |
||
424 | 5367, |
||
425 | 5414, |
||
426 | 5461, |
||
427 | 5508, |
||
428 | 5556, |
||
429 | 5603, |
||
430 | 5651, |
||
431 | 5698, |
||
432 | 5746, |
||
433 | 5794, |
||
434 | 5842, |
||
435 | 5890, |
||
436 | 5938, |
||
437 | 5987, |
||
438 | 6035, |
||
439 | 6084, |
||
440 | 6133, |
||
441 | 6182, |
||
442 | 6231, |
||
443 | 6281, |
||
444 | 6330, |
||
445 | 6380, |
||
446 | 6430, |
||
447 | 6480, |
||
448 | 6530, |
||
449 | 6580, |
||
450 | 6631, |
||
451 | 6681, |
||
452 | 6732, |
||
453 | 6783, |
||
454 | 6835, |
||
455 | 6886, |
||
456 | 6938, |
||
457 | 6990, |
||
458 | 7042, |
||
459 | 7094, |
||
460 | 7147, |
||
461 | 7199, |
||
462 | 7252, |
||
463 | 7306, |
||
464 | 7359, |
||
465 | 7413, |
||
466 | 7466, |
||
467 | 7521, |
||
468 | 7575, |
||
469 | 7630, |
||
470 | 7684, |
||
471 | 7740, |
||
472 | 7795, |
||
473 | 7851, |
||
474 | 7907, |
||
475 | 7963, |
||
476 | 8019, |
||
477 | 8076, |
||
478 | 8133, |
||
479 | 8191, |
||
480 | 8249, |
||
481 | 8307, |
||
482 | 8365, |
||
483 | 8424, |
||
484 | 8483, |
||
485 | 8543, |
||
486 | 8602, |
||
487 | 8663, |
||
488 | 8723, |
||
489 | 8784, |
||
490 | 8846, |
||
491 | 8907, |
||
492 | 8970, |
||
493 | 9032, |
||
494 | 9095, |
||
495 | 9159, |
||
496 | 9223, |
||
497 | 9288, |
||
498 | 9353, |
||
499 | 9418, |
||
500 | 9484, |
||
501 | 9551, |
||
502 | 9618, |
||
503 | 9686, |
||
504 | 9754, |
||
505 | 9823, |
||
506 | 9892, |
||
507 | 9963, |
||
508 | 10034, |
||
509 | 10105, |
||
510 | 10177, |
||
511 | 10251, |
||
512 | 10324, |
||
513 | 10399, |
||
514 | 10475, |
||
515 | 10551, |
||
516 | 10628, |
||
517 | 10706, |
||
518 | 10785, |
||
519 | 10866, |
||
520 | 10947, |
||
521 | 11029, |
||
522 | 11113, |
||
523 | 11198, |
||
524 | 11284, |
||
525 | 11371, |
||
526 | 11460, |
||
527 | 11550, |
||
528 | 11642, |
||
529 | 11736, |
||
530 | 11831, |
||
531 | 11929, |
||
532 | 12028, |
||
533 | 12130, |
||
534 | 12234, |
||
535 | 12340, |
||
536 | 12449, |
||
537 | 12561, |
||
538 | 12677, |
||
539 | 12796, |
||
540 | 12919, |
||
541 | 13046, |
||
542 | 13178, |
||
543 | 13315, |
||
544 | 13459, |
||
545 | 13610, |
||
546 | 13770, |
||
547 | 13939, |
||
548 | 14121, |
||
549 | 14319, |
||
550 | 14538, |
||
551 | 14786, |
||
552 | 15079, |
||
553 | 15462, |
||
554 | 16384, |
||
555 | 16384 // extra for when exactly 1 |
||
556 | }}; |
||
557 | |||
558 | const std::array<ushort, 258> acos_table{{ |
||
559 | 16384, |
||
560 | 16343, |
||
561 | 16303, |
||
562 | 16262, |
||
563 | 16221, |
||
564 | 16180, |
||
565 | 16140, |
||
566 | 16099, |
||
567 | 16058, |
||
568 | 16017, |
||
569 | 15976, |
||
570 | 15936, |
||
571 | 15895, |
||
572 | 15854, |
||
573 | 15813, |
||
574 | 15772, |
||
575 | 15732, |
||
576 | 15691, |
||
577 | 15650, |
||
578 | 15609, |
||
579 | 15568, |
||
580 | 15527, |
||
581 | 15487, |
||
582 | 15446, |
||
583 | 15405, |
||
584 | 15364, |
||
585 | 15323, |
||
586 | 15282, |
||
587 | 15241, |
||
588 | 15200, |
||
589 | 15159, |
||
590 | 15118, |
||
591 | 15077, |
||
592 | 15036, |
||
593 | 14995, |
||
594 | 14953, |
||
595 | 14912, |
||
596 | 14871, |
||
597 | 14830, |
||
598 | 14789, |
||
599 | 14748, |
||
600 | 14706, |
||
601 | 14665, |
||
602 | 14624, |
||
603 | 14582, |
||
604 | 14541, |
||
605 | 14500, |
||
606 | 14458, |
||
607 | 14417, |
||
608 | 14375, |
||
609 | 14334, |
||
610 | 14292, |
||
611 | 14250, |
||
612 | 14209, |
||
613 | 14167, |
||
614 | 14125, |
||
615 | 14084, |
||
616 | 14042, |
||
617 | 14000, |
||
618 | 13958, |
||
619 | 13916, |
||
620 | 13874, |
||
621 | 13833, |
||
622 | 13791, |
||
623 | 13748, |
||
624 | 13706, |
||
625 | 13664, |
||
626 | 13622, |
||
627 | 13580, |
||
628 | 13537, |
||
629 | 13495, |
||
630 | 13453, |
||
631 | 13410, |
||
632 | 13368, |
||
633 | 13325, |
||
634 | 13283, |
||
635 | 13240, |
||
636 | 13197, |
||
637 | 13155, |
||
638 | 13112, |
||
639 | 13069, |
||
640 | 13026, |
||
641 | 12983, |
||
642 | 12940, |
||
643 | 12897, |
||
644 | 12854, |
||
645 | 12811, |
||
646 | 12767, |
||
647 | 12724, |
||
648 | 12680, |
||
649 | 12637, |
||
650 | 12593, |
||
651 | 12550, |
||
652 | 12506, |
||
653 | 12462, |
||
654 | 12419, |
||
655 | 12375, |
||
656 | 12331, |
||
657 | 12287, |
||
658 | 12242, |
||
659 | 12198, |
||
660 | 12154, |
||
661 | 12109, |
||
662 | 12065, |
||
663 | 12020, |
||
664 | 11976, |
||
665 | 11931, |
||
666 | 11886, |
||
667 | 11841, |
||
668 | 11796, |
||
669 | 11751, |
||
670 | 11706, |
||
671 | 11661, |
||
672 | 11616, |
||
673 | 11570, |
||
674 | 11525, |
||
675 | 11479, |
||
676 | 11433, |
||
677 | 11387, |
||
678 | 11341, |
||
679 | 11295, |
||
680 | 11249, |
||
681 | 11203, |
||
682 | 11156, |
||
683 | 11110, |
||
684 | 11063, |
||
685 | 11017, |
||
686 | 10970, |
||
687 | 10923, |
||
688 | 10876, |
||
689 | 10828, |
||
690 | 10781, |
||
691 | 10733, |
||
692 | 10686, |
||
693 | 10638, |
||
694 | 10590, |
||
695 | 10542, |
||
696 | 10494, |
||
697 | 10446, |
||
698 | 10397, |
||
699 | 10349, |
||
700 | 10300, |
||
701 | 10251, |
||
702 | 10202, |
||
703 | 10153, |
||
704 | 10103, |
||
705 | 10054, |
||
706 | 10004, |
||
707 | 9954, |
||
708 | 9904, |
||
709 | 9854, |
||
710 | 9804, |
||
711 | 9753, |
||
712 | 9703, |
||
713 | 9652, |
||
714 | 9601, |
||
715 | 9549, |
||
716 | 9498, |
||
717 | 9446, |
||
718 | 9394, |
||
719 | 9342, |
||
720 | 9290, |
||
721 | 9237, |
||
722 | 9185, |
||
723 | 9132, |
||
724 | 9078, |
||
725 | 9025, |
||
726 | 8971, |
||
727 | 8918, |
||
728 | 8863, |
||
729 | 8809, |
||
730 | 8754, |
||
731 | 8700, |
||
732 | 8644, |
||
733 | 8589, |
||
734 | 8533, |
||
735 | 8477, |
||
736 | 8421, |
||
737 | 8365, |
||
738 | 8308, |
||
739 | 8251, |
||
740 | 8193, |
||
741 | 8135, |
||
742 | 8077, |
||
743 | 8019, |
||
744 | 7960, |
||
745 | 7901, |
||
746 | 7841, |
||
747 | 7782, |
||
748 | 7721, |
||
749 | 7661, |
||
750 | 7600, |
||
751 | 7538, |
||
752 | 7477, |
||
753 | 7414, |
||
754 | 7352, |
||
755 | 7289, |
||
756 | 7225, |
||
757 | 7161, |
||
758 | 7096, |
||
759 | 7031, |
||
760 | 6966, |
||
761 | 6900, |
||
762 | 6833, |
||
763 | 6766, |
||
764 | 6698, |
||
765 | 6630, |
||
766 | 6561, |
||
767 | 6492, |
||
768 | 6421, |
||
769 | 6350, |
||
770 | 6279, |
||
771 | 6207, |
||
772 | 6133, |
||
773 | 6060, |
||
774 | 5985, |
||
775 | 5909, |
||
776 | 5833, |
||
777 | 5756, |
||
778 | 5678, |
||
779 | 5599, |
||
780 | 5518, |
||
781 | 5437, |
||
782 | 5355, |
||
783 | 5271, |
||
784 | 5186, |
||
785 | 5100, |
||
786 | 5013, |
||
787 | 4924, |
||
788 | 4834, |
||
789 | 4742, |
||
790 | 4648, |
||
791 | 4553, |
||
792 | 4455, |
||
793 | 4356, |
||
794 | 4254, |
||
795 | 4150, |
||
796 | 4044, |
||
797 | 3935, |
||
798 | 3823, |
||
799 | 3707, |
||
800 | 3588, |
||
801 | 3465, |
||
802 | 3338, |
||
803 | 3206, |
||
804 | 3069, |
||
805 | 2925, |
||
806 | 2774, |
||
807 | 2614, |
||
808 | 2445, |
||
809 | 2263, |
||
810 | 2065, |
||
811 | 1846, |
||
812 | 1598, |
||
813 | 1305, |
||
814 | 922, |
||
815 | 0, |
||
816 | |||
817 | }}; |
||
818 | |||
819 | } |