1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: math_Triangular.cpp
4
5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 19125 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn/math.h>
17
18 #include <nn/math/math_Triangular.h>
19 #include <nn/math/math_Arithmetic.h>
20
21 namespace nn { namespace math {
22
23 namespace internal
24 {
25 //---- sin と cos のテーブル
26 const SinCosSample gSinCosTbl[256 + 1] =
27 {
28 0.0f, 1.0f, 0.0245412285229123f, -0.00030118130379575f, // rad = 0.0, deg = 0.0
29 0.0245412285229123f, 0.999698818696204f, 0.0245264458045057f, -0.000903362491031845f, // rad = 0.0245436926061703, deg = 1.40625
30 0.049067674327418f, 0.998795456205172f, 0.0244968892722494f, -0.0015049995264822f, // rad = 0.0490873852123405, deg = 2.8125
31 0.0735645635996674f, 0.99729045667869f, 0.0244525767298932f, -0.00210573000649328f, // rad = 0.0736310778185108, deg = 4.21875
32 0.0980171403295606f, 0.995184726672197f, 0.0243935348696556f, -0.00270519207348696f, // rad = 0.098174770424681, deg = 5.625
33 0.122410675199216f, 0.99247953459871f, 0.0243197992561456f, -0.00330302463392895f, // rad = 0.122718463030851, deg = 7.03125
34 0.146730474455362f, 0.989176509964781f, 0.0242314143049395f, -0.00389886757583979f, // rad = 0.147262155637022, deg = 8.4375
35 0.170961888760301f, 0.985277642388941f, 0.024128433255827f, -0.00449236198571079f, // rad = 0.171805848243192, deg = 9.84375
36 0.195090322016128f, 0.98078528040323f, 0.0240109181407416f, -0.00508315036470186f, // rad = 0.196349540849362, deg = 11.25
37 0.21910124015687f, 0.975702130038529f, 0.0238789397463941f, -0.0056708768439846f, // rad = 0.220893233455532, deg = 12.65625
38 0.242980179903264f, 0.970031253194544f, 0.0237325775716345f, -0.00625518739910413f, // rad = 0.245436926061703, deg = 14.0625
39 0.266712757474898f, 0.96377606579544f, 0.023571919779564f, -0.00683573006323102f, // rad = 0.269980618667873, deg = 15.46875
40 0.290284677254462f, 0.956940335732209f, 0.0233970631444292f, -0.00741215513917215f, // rad = 0.294524311274043, deg = 16.875
41 0.313681740398892f, 0.949528180593037f, 0.0232081129933285f, -0.00798411541001587f, // rad = 0.319068003880213, deg = 18.28125
42 0.33688985339222f, 0.941544065183021f, 0.0230051831427681f, -0.00855126634828185f, // rad = 0.343611696486384, deg = 19.6875
43 0.359895036534988f, 0.932992798834739f, 0.0227883958301017f, -0.00911326632345222f, // rad = 0.368155389092554, deg = 21.09375
44 0.38268343236509f, 0.923879532511287f, 0.0225578816399001f, -0.00966977680775605f, // rad = 0.392699081698724, deg = 22.5
45 0.40524131400499f, 0.914209755703531f, 0.0223137794252922f, -0.0102204625800874f, // rad = 0.417242774304894, deg = 23.90625
46 0.427555093430282f, 0.903989293123443f, 0.0220562362243245f, -0.010764991927928f, // rad = 0.441786466911065, deg = 25.3125
47 0.449611329654607f, 0.893224301195515f, 0.0217854071713911f, -0.0113030368471603f, // rad = 0.466330159517235, deg = 26.71875
48 0.471396736825998f, 0.881921264348355f, 0.0215014554037864f, -0.0118342732396436f, // rad = 0.490873852123405, deg = 28.125
49 0.492898192229784f, 0.870086991108711f, 0.0212045519634376f, -0.0123583811084393f, // rad = 0.515417544729575, deg = 29.53125
50 0.514102744193222f, 0.857728610000272f, 0.0208948756938755f, -0.012875044750565f, // rad = 0.539961237335746, deg = 30.9375
51 0.534997619887097f, 0.844853565249707f, 0.020572613132505f, -0.0133839529471619f, // rad = 0.564504929941916, deg = 32.34375
52 0.555570233019602f, 0.831469612302545f, 0.0202379583982432f, -0.0138847991509615f, // rad = 0.589048622548086, deg = 33.75
53 0.575808191417845f, 0.817584813151584f, 0.019891113074588f, -0.0143772816709388f, // rad = 0.613592315154257, deg = 35.15625
54 0.595699304492433f, 0.803207531480645f, 0.0195322860881935f, -0.0148611038540386f, // rad = 0.638136007760427, deg = 36.5625
55 0.615231590580627f, 0.788346427626606f, 0.0191616935830187f, -0.0153359742638693f, // rad = 0.662679700366597, deg = 37.96875
56 0.634393284163645f, 0.773010453362737f, 0.0187795587901313f, -0.0158016068562524f, // rad = 0.687223392972767, deg = 39.375
57 0.653172842953777f, 0.757208846506485f, 0.0183861118932416f, -0.0162577211515255f, // rad = 0.711767085578938, deg = 40.78125
58 0.671558954847018f, 0.740951125354959f, 0.0179815898900485f, -0.0167040424034921f, // rad = 0.736310778185108, deg = 42.1875
59 0.689540544737067f, 0.724247082951467f, 0.0175662364494806f, -0.0171403017649194f, // rad = 0.760854470791278, deg = 43.59375
60 0.707106781186547f, 0.707106781186548f, 0.0171403017649194f, -0.0175662364494806f, // rad = 0.785398163397448, deg = 45.0
61 0.724247082951467f, 0.689540544737067f, 0.0167040424034922f, -0.0179815898900486f, // rad = 0.809941856003619, deg = 46.40625
62 0.740951125354959f, 0.671558954847018f, 0.0162577211515254f, -0.0183861118932416f, // rad = 0.834485548609789, deg = 47.8125
63 0.757208846506484f, 0.653172842953777f, 0.0158016068562525f, -0.0187795587901313f, // rad = 0.859029241215959, deg = 49.21875
64 0.773010453362737f, 0.634393284163645f, 0.0153359742638692f, -0.0191616935830187f, // rad = 0.883572933822129, deg = 50.625
65 0.788346427626606f, 0.615231590580627f, 0.0148611038540386f, -0.0195322860881934f, // rad = 0.9081166264283, deg = 52.03125
66 0.803207531480645f, 0.595699304492433f, 0.0143772816709389f, -0.0198911130745881f, // rad = 0.93266031903447, deg = 53.4375
67 0.817584813151584f, 0.575808191417845f, 0.0138847991509615f, -0.0202379583982431f, // rad = 0.95720401164064, deg = 54.84375
68 0.831469612302545f, 0.555570233019602f, 0.0133839529471618f, -0.020572613132505f, // rad = 0.98174770424681, deg = 56.25
69 0.844853565249707f, 0.534997619887097f, 0.0128750447505651f, -0.0208948756938756f, // rad = 1.00629139685298, deg = 57.65625
70 0.857728610000272f, 0.514102744193222f, 0.0123583811084392f, -0.0212045519634376f, // rad = 1.03083508945915, deg = 59.0625
71 0.870086991108711f, 0.492898192229784f, 0.0118342732396436f, -0.0215014554037863f, // rad = 1.05537878206532, deg = 60.46875
72 0.881921264348355f, 0.471396736825998f, 0.0113030368471604f, -0.0217854071713912f, // rad = 1.07992247467149, deg = 61.875
73 0.893224301195515f, 0.449611329654607f, 0.010764991927928f, -0.0220562362243244f, // rad = 1.10446616727766, deg = 63.28125
74 0.903989293123443f, 0.427555093430282f, 0.0102204625800874f, -0.0223137794252923f, // rad = 1.12900985988383, deg = 64.6875
75 0.914209755703531f, 0.40524131400499f, 0.00966977680775605f, -0.0225578816399f, // rad = 1.15355355249, deg = 66.09375
76 0.923879532511287f, 0.38268343236509f, 0.00911326632345211f, -0.0227883958301016f, // rad = 1.17809724509617, deg = 67.5
77 0.932992798834739f, 0.359895036534988f, 0.00855126634828196f, -0.0230051831427682f, // rad = 1.20264093770234, deg = 68.90625
78 0.941544065183021f, 0.33688985339222f, 0.00798411541001587f, -0.0232081129933285f, // rad = 1.22718463030851, deg = 70.3125
79 0.949528180593037f, 0.313681740398892f, 0.00741215513917226f, -0.0233970631444292f, // rad = 1.25172832291468, deg = 71.71875
80 0.956940335732209f, 0.290284677254462f, 0.0068357300632309f, -0.0235719197795639f, // rad = 1.27627201552085, deg = 73.125
81 0.96377606579544f, 0.266712757474898f, 0.00625518739910413f, -0.0237325775716344f, // rad = 1.30081570812702, deg = 74.53125
82 0.970031253194544f, 0.242980179903264f, 0.0056708768439846f, -0.0238789397463942f, // rad = 1.32535940073319, deg = 75.9375
83 0.975702130038529f, 0.21910124015687f, 0.00508315036470186f, -0.0240109181407414f, // rad = 1.34990309333936, deg = 77.34375
84 0.98078528040323f, 0.195090322016128f, 0.00449236198571079f, -0.024128433255827f, // rad = 1.37444678594553, deg = 78.75
85 0.985277642388941f, 0.170961888760301f, 0.00389886757583979f, -0.0242314143049396f, // rad = 1.3989904785517, deg = 80.15625
86 0.989176509964781f, 0.146730474455362f, 0.00330302463392895f, -0.0243197992561455f, // rad = 1.42353417115788, deg = 81.5625
87 0.99247953459871f, 0.122410675199216f, 0.00270519207348685f, -0.0243935348696555f, // rad = 1.44807786376405, deg = 82.96875
88 0.995184726672197f, 0.0980171403295608f, 0.00210573000649339f, -0.0244525767298933f, // rad = 1.47262155637022, deg = 84.375
89 0.99729045667869f, 0.0735645635996675f, 0.0015049995264822f, -0.0244968892722493f, // rad = 1.49716524897639, deg = 85.78125
90 0.998795456205172f, 0.0490676743274181f, 0.000903362491031845f, -0.0245264458045059f, // rad = 1.52170894158256, deg = 87.1875
91 0.999698818696204f, 0.0245412285229123f, 0.00030118130379575f, -0.0245412285229122f, // rad = 1.54625263418873, deg = 88.59375
92 1.0f, 0.0f, -0.00030118130379575f, -0.0245412285229122f, // rad = 1.5707963267949, deg = 90.0
93 0.999698818696204f, -0.0245412285229121f, -0.000903362491031845f, -0.0245264458045059f, // rad = 1.59534001940107, deg = 91.40625
94 0.998795456205172f, -0.049067674327418f, -0.0015049995264822f, -0.0244968892722493f, // rad = 1.61988371200724, deg = 92.8125
95 0.99729045667869f, -0.0735645635996673f, -0.00210573000649328f, -0.0244525767298933f, // rad = 1.64442740461341, deg = 94.21875
96 0.995184726672197f, -0.0980171403295606f, -0.00270519207348696f, -0.0243935348696555f, // rad = 1.66897109721958, deg = 95.625
97 0.99247953459871f, -0.122410675199216f, -0.00330302463392895f, -0.0243197992561455f, // rad = 1.69351478982575, deg = 97.03125
98 0.989176509964781f, -0.146730474455362f, -0.00389886757583979f, -0.0242314143049396f, // rad = 1.71805848243192, deg = 98.4375
99 0.985277642388941f, -0.170961888760301f, -0.00449236198571079f, -0.0241284332558269f, // rad = 1.74260217503809, deg = 99.84375
100 0.98078528040323f, -0.195090322016128f, -0.00508315036470186f, -0.0240109181407415f, // rad = 1.76714586764426, deg = 101.25
101 0.975702130038529f, -0.21910124015687f, -0.0056708768439846f, -0.0238789397463942f, // rad = 1.79168956025043, deg = 102.65625
102 0.970031253194544f, -0.242980179903264f, -0.00625518739910413f, -0.0237325775716344f, // rad = 1.8162332528566, deg = 104.0625
103 0.96377606579544f, -0.266712757474898f, -0.0068357300632309f, -0.0235719197795639f, // rad = 1.84077694546277, deg = 105.46875
104 0.956940335732209f, -0.290284677254462f, -0.00741215513917226f, -0.0233970631444292f, // rad = 1.86532063806894, deg = 106.875
105 0.949528180593037f, -0.313681740398891f, -0.00798411541001587f, -0.0232081129933285f, // rad = 1.88986433067511, deg = 108.28125
106 0.941544065183021f, -0.33688985339222f, -0.00855126634828196f, -0.0230051831427682f, // rad = 1.91440802328128, deg = 109.6875
107 0.932992798834739f, -0.359895036534988f, -0.00911326632345211f, -0.0227883958301016f, // rad = 1.93895171588745, deg = 111.09375
108 0.923879532511287f, -0.38268343236509f, -0.00966977680775605f, -0.0225578816399f, // rad = 1.96349540849362, deg = 112.5
109 0.914209755703531f, -0.40524131400499f, -0.0102204625800872f, -0.0223137794252921f, // rad = 1.98803910109979, deg = 113.90625
110 0.903989293123443f, -0.427555093430282f, -0.0107649919279282f, -0.0220562362243248f, // rad = 2.01258279370596, deg = 115.3125
111 0.893224301195515f, -0.449611329654607f, -0.0113030368471602f, -0.021785407171391f, // rad = 2.03712648631213, deg = 116.71875
112 0.881921264348355f, -0.471396736825998f, -0.0118342732396436f, -0.0215014554037863f, // rad = 2.0616701789183, deg = 118.125
113 0.870086991108711f, -0.492898192229784f, -0.0123583811084393f, -0.0212045519634377f, // rad = 2.08621387152447, deg = 119.53125
114 0.857728610000272f, -0.514102744193222f, -0.0128750447505649f, -0.0208948756938754f, // rad = 2.11075756413064, deg = 120.9375
115 0.844853565249707f, -0.534997619887097f, -0.0133839529471618f, -0.0205726131325049f, // rad = 2.13530125673681, deg = 122.34375
116 0.831469612302545f, -0.555570233019602f, -0.0138847991509617f, -0.0202379583982434f, // rad = 2.15984494934298, deg = 123.75
117 0.817584813151584f, -0.575808191417845f, -0.0143772816709388f, -0.019891113074588f, // rad = 2.18438864194915, deg = 125.15625
118 0.803207531480645f, -0.595699304492433f, -0.0148611038540386f, -0.0195322860881934f, // rad = 2.20893233455532, deg = 126.5625
119 0.788346427626606f, -0.615231590580627f, -0.0153359742638692f, -0.0191616935830187f, // rad = 2.23347602716149, deg = 127.96875
120 0.773010453362737f, -0.634393284163645f, -0.0158016068562524f, -0.0187795587901312f, // rad = 2.25801971976766, deg = 129.375
121 0.757208846506485f, -0.653172842953777f, -0.0162577211515257f, -0.0183861118932419f, // rad = 2.28256341237383, deg = 130.78125
122 0.740951125354959f, -0.671558954847018f, -0.0167040424034921f, -0.0179815898900485f, // rad = 2.30710710498, deg = 132.1875
123 0.724247082951467f, -0.689540544737067f, -0.0171403017649193f, -0.0175662364494805f, // rad = 2.33165079758617, deg = 133.59375
124 0.707106781186548f, -0.707106781186547f, -0.0175662364494805f, -0.0171403017649193f, // rad = 2.35619449019234, deg = 135.0
125 0.689540544737067f, -0.724247082951467f, -0.0179815898900485f, -0.0167040424034921f, // rad = 2.38073818279852, deg = 136.40625
126 0.671558954847019f, -0.740951125354959f, -0.0183861118932419f, -0.0162577211515257f, // rad = 2.40528187540469, deg = 137.8125
127 0.653172842953777f, -0.757208846506485f, -0.0187795587901312f, -0.0158016068562524f, // rad = 2.42982556801086, deg = 139.21875
128 0.634393284163645f, -0.773010453362737f, -0.0191616935830186f, -0.0153359742638692f, // rad = 2.45436926061703, deg = 140.625
129 0.615231590580627f, -0.788346427626606f, -0.0195322860881935f, -0.0148611038540386f, // rad = 2.4789129532232, deg = 142.03125
130 0.595699304492433f, -0.803207531480645f, -0.019891113074588f, -0.0143772816709388f, // rad = 2.50345664582937, deg = 143.4375
131 0.575808191417845f, -0.817584813151584f, -0.0202379583982433f, -0.0138847991509617f, // rad = 2.52800033843554, deg = 144.84375
132 0.555570233019602f, -0.831469612302545f, -0.020572613132505f, -0.0133839529471618f, // rad = 2.55254403104171, deg = 146.25
133 0.534997619887097f, -0.844853565249707f, -0.0208948756938754f, -0.0128750447505649f, // rad = 2.57708772364788, deg = 147.65625
134 0.514102744193222f, -0.857728610000272f, -0.0212045519634376f, -0.0123583811084393f, // rad = 2.60163141625405, deg = 149.0625
135 0.492898192229784f, -0.870086991108711f, -0.0215014554037863f, -0.0118342732396436f, // rad = 2.62617510886022, deg = 150.46875
136 0.471396736825998f, -0.881921264348355f, -0.021785407171391f, -0.0113030368471603f, // rad = 2.65071880146639, deg = 151.875
137 0.449611329654607f, -0.893224301195515f, -0.0220562362243248f, -0.0107649919279281f, // rad = 2.67526249407256, deg = 153.28125
138 0.427555093430282f, -0.903989293123443f, -0.0223137794252921f, -0.0102204625800874f, // rad = 2.69980618667873, deg = 154.6875
139 0.40524131400499f, -0.914209755703531f, -0.0225578816399f, -0.00966977680775605f, // rad = 2.7243498792849, deg = 156.09375
140 0.38268343236509f, -0.923879532511287f, -0.0227883958301016f, -0.00911326632345211f, // rad = 2.74889357189107, deg = 157.5
141 0.359895036534988f, -0.932992798834739f, -0.023005183142768f, -0.00855126634828185f, // rad = 2.77343726449724, deg = 158.90625
142 0.33688985339222f, -0.941544065183021f, -0.0232081129933289f, -0.00798411541001598f, // rad = 2.79798095710341, deg = 160.3125
143 0.313681740398891f, -0.949528180593037f, -0.023397063144429f, -0.00741215513917215f, // rad = 2.82252464970958, deg = 161.71875
144 0.290284677254462f, -0.956940335732209f, -0.0235719197795639f, -0.00683573006323102f, // rad = 2.84706834231575, deg = 163.125
145 0.266712757474898f, -0.96377606579544f, -0.0237325775716344f, -0.00625518739910413f, // rad = 2.87161203492192, deg = 164.53125
146 0.242980179903264f, -0.970031253194544f, -0.023878939746394f, -0.00567087684398448f, // rad = 2.89615572752809, deg = 165.9375
147 0.21910124015687f, -0.975702130038528f, -0.0240109181407414f, -0.00508315036470197f, // rad = 2.92069942013426, deg = 167.34375
148 0.195090322016129f, -0.98078528040323f, -0.0241284332558274f, -0.00449236198571079f, // rad = 2.94524311274043, deg = 168.75
149 0.170961888760301f, -0.985277642388941f, -0.0242314143049394f, -0.00389886757583979f, // rad = 2.9697868053466, deg = 170.15625
150 0.146730474455362f, -0.989176509964781f, -0.0243197992561455f, -0.00330302463392895f, // rad = 2.99433049795277, deg = 171.5625
151 0.122410675199216f, -0.99247953459871f, -0.0243935348696555f, -0.00270519207348685f, // rad = 3.01887419055894, deg = 172.96875
152 0.0980171403295608f, -0.995184726672197f, -0.0244525767298931f, -0.00210573000649339f, // rad = 3.04341788316511, deg = 174.375
153 0.0735645635996677f, -0.99729045667869f, -0.0244968892722498f, -0.0015049995264822f, // rad = 3.06796157577128, deg = 175.78125
154 0.049067674327418f, -0.998795456205172f, -0.0245264458045056f, -0.000903362491031845f, // rad = 3.09250526837745, deg = 177.1875
155 0.0245412285229123f, -0.999698818696204f, -0.0245412285229122f, -0.00030118130379575f, // rad = 3.11704896098362, deg = 178.59375
156 0.0f, -1.0f, -0.0245412285229122f, 0.00030118130379575f, // rad = 3.14159265358979, deg = 180.0
157 -0.0245412285229121f, -0.999698818696204f, -0.0245264458045056f, 0.000903362491031845f, // rad = 3.16613634619596, deg = 181.40625
158 -0.0490676743274177f, -0.998795456205172f, -0.0244968892722498f, 0.0015049995264822f, // rad = 3.19068003880213, deg = 182.8125
159 -0.0735645635996675f, -0.99729045667869f, -0.0244525767298931f, 0.00210573000649328f, // rad = 3.2152237314083, deg = 184.21875
160 -0.0980171403295606f, -0.995184726672197f, -0.0243935348696555f, 0.00270519207348696f, // rad = 3.23976742401447, deg = 185.625
161 -0.122410675199216f, -0.99247953459871f, -0.0243197992561455f, 0.00330302463392895f, // rad = 3.26431111662064, deg = 187.03125
162 -0.146730474455362f, -0.989176509964781f, -0.0242314143049394f, 0.00389886757583968f, // rad = 3.28885480922681, deg = 188.4375
163 -0.170961888760301f, -0.985277642388941f, -0.0241284332558274f, 0.0044923619857109f, // rad = 3.31339850183298, deg = 189.84375
164 -0.195090322016128f, -0.98078528040323f, -0.0240109181407414f, 0.00508315036470186f, // rad = 3.33794219443916, deg = 191.25
165 -0.21910124015687f, -0.975702130038529f, -0.023878939746394f, 0.0056708768439846f, // rad = 3.36248588704533, deg = 192.65625
166 -0.242980179903264f, -0.970031253194544f, -0.0237325775716344f, 0.00625518739910402f, // rad = 3.3870295796515, deg = 194.0625
167 -0.266712757474898f, -0.96377606579544f, -0.0235719197795639f, 0.00683573006323102f, // rad = 3.41157327225767, deg = 195.46875
168 -0.290284677254462f, -0.956940335732209f, -0.0233970631444291f, 0.00741215513917215f, // rad = 3.43611696486384, deg = 196.875
169 -0.313681740398891f, -0.949528180593037f, -0.0232081129933289f, 0.00798411541001598f, // rad = 3.46066065747001, deg = 198.28125
170 -0.33688985339222f, -0.941544065183021f, -0.023005183142768f, 0.00855126634828185f, // rad = 3.48520435007618, deg = 199.6875
171 -0.359895036534988f, -0.932992798834739f, -0.0227883958301016f, 0.00911326632345211f, // rad = 3.50974804268235, deg = 201.09375
172 -0.38268343236509f, -0.923879532511287f, -0.0225578816399f, 0.00966977680775616f, // rad = 3.53429173528852, deg = 202.5
173 -0.40524131400499f, -0.914209755703531f, -0.0223137794252921f, 0.0102204625800872f, // rad = 3.55883542789469, deg = 203.90625
174 -0.427555093430282f, -0.903989293123443f, -0.0220562362243248f, 0.0107649919279281f, // rad = 3.58337912050086, deg = 205.3125
175 -0.449611329654607f, -0.893224301195515f, -0.021785407171391f, 0.0113030368471603f, // rad = 3.60792281310703, deg = 206.71875
176 -0.471396736825998f, -0.881921264348355f, -0.0215014554037863f, 0.0118342732396436f, // rad = 3.6324665057132, deg = 208.125
177 -0.492898192229784f, -0.870086991108711f, -0.0212045519634376f, 0.0123583811084393f, // rad = 3.65701019831937, deg = 209.53125
178 -0.514102744193222f, -0.857728610000272f, -0.0208948756938754f, 0.0128750447505649f, // rad = 3.68155389092554, deg = 210.9375
179 -0.534997619887097f, -0.844853565249707f, -0.020572613132505f, 0.0133839529471618f, // rad = 3.70609758353171, deg = 212.34375
180 -0.555570233019602f, -0.831469612302545f, -0.0202379583982434f, 0.0138847991509617f, // rad = 3.73064127613788, deg = 213.75
181 -0.575808191417845f, -0.817584813151584f, -0.0198911130745879f, 0.0143772816709388f, // rad = 3.75518496874405, deg = 215.15625
182 -0.595699304492433f, -0.803207531480645f, -0.0195322860881935f, 0.0148611038540386f, // rad = 3.77972866135022, deg = 216.5625
183 -0.615231590580627f, -0.788346427626606f, -0.0191616935830186f, 0.0153359742638692f, // rad = 3.80427235395639, deg = 217.96875
184 -0.634393284163645f, -0.773010453362737f, -0.0187795587901313f, 0.0158016068562523f, // rad = 3.82881604656256, deg = 219.375
185 -0.653172842953777f, -0.757208846506485f, -0.0183861118932419f, 0.0162577211515257f, // rad = 3.85335973916873, deg = 220.78125
186 -0.671558954847018f, -0.740951125354959f, -0.0179815898900484f, 0.0167040424034921f, // rad = 3.8779034317749, deg = 222.1875
187 -0.689540544737067f, -0.724247082951467f, -0.0175662364494806f, 0.0171403017649193f, // rad = 3.90244712438107, deg = 223.59375
188 -0.707106781186547f, -0.707106781186548f, -0.0171403017649193f, 0.0175662364494806f, // rad = 3.92699081698724, deg = 225.0
189 -0.724247082951467f, -0.689540544737067f, -0.0167040424034921f, 0.0179815898900484f, // rad = 3.95153450959341, deg = 226.40625
190 -0.740951125354959f, -0.671558954847019f, -0.0162577211515254f, 0.0183861118932416f, // rad = 3.97607820219958, deg = 227.8125
191 -0.757208846506484f, -0.653172842953777f, -0.0158016068562524f, 0.0187795587901312f, // rad = 4.00062189480575, deg = 229.21875
192 -0.773010453362737f, -0.634393284163646f, -0.0153359742638692f, 0.0191616935830187f, // rad = 4.02516558741192, deg = 230.625
193 -0.788346427626606f, -0.615231590580627f, -0.0148611038540392f, 0.0195322860881941f, // rad = 4.04970928001809, deg = 232.03125
194 -0.803207531480645f, -0.595699304492433f, -0.0143772816709388f, 0.0198911130745879f, // rad = 4.07425297262426, deg = 233.4375
195 -0.817584813151584f, -0.575808191417845f, -0.0138847991509614f, 0.0202379583982431f, // rad = 4.09879666523043, deg = 234.84375
196 -0.831469612302545f, -0.555570233019602f, -0.0133839529471618f, 0.0205726131325049f, // rad = 4.1233403578366, deg = 236.25
197 -0.844853565249707f, -0.534997619887097f, -0.012875044750565f, 0.0208948756938755f, // rad = 4.14788405044277, deg = 237.65625
198 -0.857728610000272f, -0.514102744193222f, -0.0123583811084393f, 0.0212045519634376f, // rad = 4.17242774304894, deg = 239.0625
199 -0.870086991108711f, -0.492898192229784f, -0.0118342732396436f, 0.0215014554037863f, // rad = 4.19697143565511, deg = 240.46875
200 -0.881921264348355f, -0.471396736825998f, -0.0113030368471603f, 0.0217854071713909f, // rad = 4.22151512826128, deg = 241.875
201 -0.893224301195515f, -0.449611329654607f, -0.0107649919279279f, 0.0220562362243245f, // rad = 4.24605882086745, deg = 243.28125
202 -0.903989293123443f, -0.427555093430282f, -0.0102204625800874f, 0.0223137794252921f, // rad = 4.27060251347362, deg = 244.6875
203 -0.91420975570353f, -0.40524131400499f, -0.00966977680775605f, 0.0225578816399f, // rad = 4.29514620607979, deg = 246.09375
204 -0.923879532511287f, -0.38268343236509f, -0.00911326632345244f, 0.0227883958301024f, // rad = 4.31968989868597, deg = 247.5
205 -0.932992798834739f, -0.359895036534988f, -0.00855126634828185f, 0.023005183142768f, // rad = 4.34423359129214, deg = 248.90625
206 -0.941544065183021f, -0.33688985339222f, -0.00798411541001587f, 0.0232081129933285f, // rad = 4.36877728389831, deg = 250.3125
207 -0.949528180593037f, -0.313681740398891f, -0.00741215513917215f, 0.023397063144429f, // rad = 4.39332097650448, deg = 251.71875
208 -0.956940335732209f, -0.290284677254462f, -0.00683573006323102f, 0.0235719197795639f, // rad = 4.41786466911065, deg = 253.125
209 -0.96377606579544f, -0.266712757474899f, -0.00625518739910413f, 0.0237325775716344f, // rad = 4.44240836171682, deg = 254.53125
210 -0.970031253194544f, -0.242980179903264f, -0.00567087684398448f, 0.023878939746394f, // rad = 4.46695205432299, deg = 255.9375
211 -0.975702130038528f, -0.21910124015687f, -0.00508315036470186f, 0.0240109181407414f, // rad = 4.49149574692916, deg = 257.34375
212 -0.98078528040323f, -0.195090322016129f, -0.00449236198571079f, 0.024128433255827f, // rad = 4.51603943953533, deg = 258.75
213 -0.985277642388941f, -0.170961888760302f, -0.00389886757583979f, 0.0242314143049394f, // rad = 4.5405831321415, deg = 260.15625
214 -0.989176509964781f, -0.146730474455362f, -0.00330302463392917f, 0.0243197992561463f, // rad = 4.56512682474767, deg = 261.5625
215 -0.99247953459871f, -0.122410675199216f, -0.00270519207348685f, 0.0243935348696555f, // rad = 4.58967051735384, deg = 262.96875
216 -0.995184726672197f, -0.0980171403295605f, -0.00210573000649328f, 0.0244525767298931f, // rad = 4.61421420996001, deg = 264.375
217 -0.99729045667869f, -0.0735645635996674f, -0.0015049995264822f, 0.0244968892722493f, // rad = 4.63875790256618, deg = 265.78125
218 -0.998795456205172f, -0.049067674327418f, -0.000903362491031845f, 0.0245264458045056f, // rad = 4.66330159517235, deg = 267.1875
219 -0.999698818696204f, -0.0245412285229124f, -0.00030118130379575f, 0.0245412285229122f, // rad = 4.68784528777852, deg = 268.59375
220 -1.0f, 0.0f, 0.00030118130379575f, 0.0245412285229122f, // rad = 4.71238898038469, deg = 270.0
221 -0.999698818696204f, 0.024541228522912f, 0.000903362491031845f, 0.0245264458045056f, // rad = 4.73693267299086, deg = 271.40625
222 -0.998795456205172f, 0.0490676743274177f, 0.0015049995264822f, 0.0244968892722493f, // rad = 4.76147636559703, deg = 272.8125
223 -0.99729045667869f, 0.073564563599667f, 0.00210573000649328f, 0.0244525767298931f, // rad = 4.7860200582032, deg = 274.21875
224 -0.995184726672197f, 0.0980171403295601f, 0.00270519207348685f, 0.0243935348696555f, // rad = 4.81056375080937, deg = 275.625
225 -0.99247953459871f, 0.122410675199216f, 0.00330302463392917f, 0.0243197992561463f, // rad = 4.83510744341554, deg = 277.03125
226 -0.989176509964781f, 0.146730474455362f, 0.00389886757583968f, 0.0242314143049394f, // rad = 4.85965113602171, deg = 278.4375
227 -0.985277642388941f, 0.170961888760301f, 0.00449236198571079f, 0.024128433255827f, // rad = 4.88419482862788, deg = 279.84375
228 -0.98078528040323f, 0.195090322016128f, 0.00508315036470186f, 0.0240109181407414f, // rad = 4.90873852123405, deg = 281.25
229 -0.975702130038529f, 0.21910124015687f, 0.0056708768439846f, 0.023878939746394f, // rad = 4.93328221384022, deg = 282.65625
230 -0.970031253194544f, 0.242980179903264f, 0.00625518739910402f, 0.0237325775716344f, // rad = 4.95782590644639, deg = 284.0625
231 -0.96377606579544f, 0.266712757474898f, 0.00683573006323102f, 0.0235719197795639f, // rad = 4.98236959905256, deg = 285.46875
232 -0.956940335732209f, 0.290284677254462f, 0.00741215513917215f, 0.0233970631444291f, // rad = 5.00691329165873, deg = 286.875
233 -0.949528180593037f, 0.313681740398891f, 0.00798411541001587f, 0.0232081129933285f, // rad = 5.0314569842649, deg = 288.28125
234 -0.941544065183021f, 0.33688985339222f, 0.00855126634828185f, 0.023005183142768f, // rad = 5.05600067687107, deg = 289.6875
235 -0.932992798834739f, 0.359895036534988f, 0.00911326632345244f, 0.0227883958301024f, // rad = 5.08054436947724, deg = 291.09375
236 -0.923879532511287f, 0.38268343236509f, 0.00966977680775605f, 0.0225578816399f, // rad = 5.10508806208341, deg = 292.5
237 -0.914209755703531f, 0.40524131400499f, 0.0102204625800872f, 0.0223137794252921f, // rad = 5.12963175468958, deg = 293.90625
238 -0.903989293123443f, 0.427555093430282f, 0.010764991927928f, 0.0220562362243245f, // rad = 5.15417544729575, deg = 295.3125
239 -0.893224301195515f, 0.449611329654607f, 0.0113030368471603f, 0.021785407171391f, // rad = 5.17871913990192, deg = 296.71875
240 -0.881921264348355f, 0.471396736825998f, 0.0118342732396436f, 0.0215014554037863f, // rad = 5.2032628325081, deg = 298.125
241 -0.870086991108711f, 0.492898192229784f, 0.0123583811084392f, 0.0212045519634377f, // rad = 5.22780652511427, deg = 299.53125
242 -0.857728610000272f, 0.514102744193222f, 0.012875044750565f, 0.0208948756938754f, // rad = 5.25235021772044, deg = 300.9375
243 -0.844853565249707f, 0.534997619887097f, 0.0133839529471618f, 0.0205726131325049f, // rad = 5.27689391032661, deg = 302.34375
244 -0.831469612302545f, 0.555570233019602f, 0.0138847991509614f, 0.0202379583982431f, // rad = 5.30143760293278, deg = 303.75
245 -0.817584813151584f, 0.575808191417845f, 0.0143772816709388f, 0.019891113074588f, // rad = 5.32598129553895, deg = 305.15625
246 -0.803207531480645f, 0.595699304492433f, 0.0148611038540392f, 0.0195322860881941f, // rad = 5.35052498814512, deg = 306.5625
247 -0.788346427626606f, 0.615231590580627f, 0.0153359742638692f, 0.0191616935830186f, // rad = 5.37506868075129, deg = 307.96875
248 -0.773010453362737f, 0.634393284163646f, 0.0158016068562523f, 0.0187795587901312f, // rad = 5.39961237335746, deg = 309.375
249 -0.757208846506485f, 0.653172842953777f, 0.0162577211515255f, 0.0183861118932416f, // rad = 5.42415606596363, deg = 310.78125
250 -0.740951125354959f, 0.671558954847018f, 0.0167040424034921f, 0.0179815898900485f, // rad = 5.4486997585698, deg = 312.1875
251 -0.724247082951467f, 0.689540544737067f, 0.0171403017649193f, 0.0175662364494805f, // rad = 5.47324345117597, deg = 313.59375
252 -0.707106781186548f, 0.707106781186547f, 0.0175662364494805f, 0.0171403017649193f, // rad = 5.49778714378214, deg = 315.0
253 -0.689540544737067f, 0.724247082951467f, 0.0179815898900485f, 0.0167040424034922f, // rad = 5.52233083638831, deg = 316.40625
254 -0.671558954847019f, 0.740951125354959f, 0.0183861118932416f, 0.0162577211515254f, // rad = 5.54687452899448, deg = 317.8125
255 -0.653172842953777f, 0.757208846506484f, 0.0187795587901312f, 0.0158016068562524f, // rad = 5.57141822160065, deg = 319.21875
256 -0.634393284163646f, 0.773010453362737f, 0.0191616935830186f, 0.0153359742638692f, // rad = 5.59596191420682, deg = 320.625
257 -0.615231590580627f, 0.788346427626606f, 0.0195322860881941f, 0.0148611038540392f, // rad = 5.62050560681299, deg = 322.03125
258 -0.595699304492433f, 0.803207531480645f, 0.019891113074588f, 0.0143772816709387f, // rad = 5.64504929941916, deg = 323.4375
259 -0.575808191417845f, 0.817584813151584f, 0.0202379583982431f, 0.0138847991509615f, // rad = 5.66959299202533, deg = 324.84375
260 -0.555570233019602f, 0.831469612302545f, 0.0205726131325049f, 0.0133839529471618f, // rad = 5.6941366846315, deg = 326.25
261 -0.534997619887097f, 0.844853565249707f, 0.0208948756938754f, 0.012875044750565f, // rad = 5.71868037723767, deg = 327.65625
262 -0.514102744193222f, 0.857728610000272f, 0.0212045519634376f, 0.0123583811084393f, // rad = 5.74322406984384, deg = 329.0625
263 -0.492898192229784f, 0.870086991108711f, 0.0215014554037863f, 0.0118342732396435f, // rad = 5.76776776245001, deg = 330.46875
264 -0.471396736825998f, 0.881921264348355f, 0.0217854071713909f, 0.0113030368471603f, // rad = 5.79231145505618, deg = 331.875
265 -0.449611329654607f, 0.893224301195515f, 0.0220562362243245f, 0.010764991927928f, // rad = 5.81685514766235, deg = 333.28125
266 -0.427555093430283f, 0.903989293123443f, 0.0223137794252921f, 0.0102204625800874f, // rad = 5.84139884026852, deg = 334.6875
267 -0.40524131400499f, 0.91420975570353f, 0.0225578816399f, 0.00966977680775605f, // rad = 5.86594253287469, deg = 336.09375
268 -0.38268343236509f, 0.923879532511287f, 0.0227883958301024f, 0.00911326632345244f, // rad = 5.89048622548086, deg = 337.5
269 -0.359895036534988f, 0.932992798834739f, 0.023005183142768f, 0.00855126634828185f, // rad = 5.91502991808703, deg = 338.90625
270 -0.33688985339222f, 0.941544065183021f, 0.0232081129933285f, 0.00798411541001587f, // rad = 5.9395736106932, deg = 340.3125
271 -0.313681740398892f, 0.949528180593037f, 0.023397063144429f, 0.00741215513917215f, // rad = 5.96411730329937, deg = 341.71875
272 -0.290284677254463f, 0.956940335732209f, 0.0235719197795639f, 0.00683573006323102f, // rad = 5.98866099590554, deg = 343.125
273 -0.266712757474899f, 0.96377606579544f, 0.0237325775716344f, 0.00625518739910413f, // rad = 6.01320468851171, deg = 344.53125
274 -0.242980179903264f, 0.970031253194544f, 0.023878939746394f, 0.00567087684398448f, // rad = 6.03774838111788, deg = 345.9375
275 -0.21910124015687f, 0.975702130038528f, 0.0240109181407414f, 0.00508315036470186f, // rad = 6.06229207372405, deg = 347.34375
276 -0.195090322016129f, 0.98078528040323f, 0.0241284332558269f, 0.00449236198571079f, // rad = 6.08683576633022, deg = 348.75
277 -0.170961888760302f, 0.985277642388941f, 0.0242314143049394f, 0.00389886757583979f, // rad = 6.11137945893639, deg = 350.15625
278 -0.146730474455362f, 0.989176509964781f, 0.0243197992561464f, 0.00330302463392906f, // rad = 6.13592315154256, deg = 351.5625
279 -0.122410675199216f, 0.99247953459871f, 0.0243935348696555f, 0.00270519207348696f, // rad = 6.16046684414874, deg = 352.96875
280 -0.0980171403295605f, 0.995184726672197f, 0.0244525767298931f, 0.00210573000649328f, // rad = 6.18501053675491, deg = 354.375
281 -0.0735645635996674f, 0.99729045667869f, 0.0244968892722493f, 0.0015049995264822f, // rad = 6.20955422936108, deg = 355.78125
282 -0.0490676743274181f, 0.998795456205172f, 0.0245264458045056f, 0.000903362491031845f, // rad = 6.23409792196725, deg = 357.1875
283 -0.0245412285229124f, 0.999698818696204f, 0.0245412285229122f, 0.00030118130379575f, // rad = 6.25864161457342, deg = 358.59375
284 0.0f, 1.0f, 0.0245412285229122f, -0.00030118130379575f, // rad = 6.28318530717959, deg = 360.0
285 };
286
287 } // end of namespace internal
288
289 namespace
290 {
291 //---- atan のテーブル
292 typedef struct AtanValue
293 {
294 f32 atan_val;
295 f32 atan_delta;
296 } ATanValue;
297
298 AtanValue sArcTanTbl[32+1] =
299 {
300 { 0.000000000f, 1.272825321f}, // Atan(0.00000) * 256/2pi
301 { 1.272825321f, 1.270345790f}, // Atan(0.03125) * 256/2pi
302 { 2.543171111f, 1.265415586f}, // Atan(0.06250) * 256/2pi
303 { 3.808586697f, 1.258091595f}, // Atan(0.09375) * 256/2pi
304 { 5.066678293f, 1.248457103f}, // Atan(0.12500) * 256/2pi
305 { 6.315135396f, 1.236619467f}, // Atan(0.15625) * 256/2pi
306 { 7.551754863f, 1.222707202f}, // Atan(0.18750) * 256/2pi
307 { 8.774462065f, 1.206866624f}, // Atan(0.21875) * 256/2pi
308 { 9.981328688f, 1.189258212f}, // Atan(0.25000) * 256/2pi
309 { 11.170586901f, 1.170052841f}, // Atan(0.28125) * 256/2pi
310 { 12.340639741f, 1.149428034f}, // Atan(0.31250) * 256/2pi
311 { 13.490067775f, 1.127564381f}, // Atan(0.34375) * 256/2pi
312 { 14.617632156f, 1.104642222f}, // Atan(0.37500) * 256/2pi
313 { 15.722274378f, 1.080838675f}, // Atan(0.40625) * 256/2pi
314 { 16.803113053f, 1.056325088f}, // Atan(0.43750) * 256/2pi
315 { 17.859438141f, 1.031264918f}, // Atan(0.46875) * 256/2pi
316 { 18.890703059f, 1.005812061f}, // Atan(0.50000) * 256/2pi
317 { 19.896515121f, 0.980109621f}, // Atan(0.53125) * 256/2pi
318 { 20.876624742f, 0.954289072f}, // Atan(0.56250) * 256/2pi
319 { 21.830913814f, 0.928469801f}, // Atan(0.59375) * 256/2pi
320 { 22.759383615f, 0.902758952f}, // Atan(0.62500) * 256/2pi
321 { 23.662142567f, 0.877251558f}, // Atan(0.65625) * 256/2pi
322 { 24.539394125f, 0.852030871f}, // Atan(0.68750) * 256/2pi
323 { 25.391424996f, 0.827168886f}, // Atan(0.71875) * 256/2pi
324 { 26.218593881f, 0.802726967f}, // Atan(0.75000) * 256/2pi
325 { 27.021320848f, 0.778756582f}, // Atan(0.78125) * 256/2pi
326 { 27.800077430f, 0.755300081f}, // Atan(0.81250) * 256/2pi
327 { 28.555377511f, 0.732391496f}, // Atan(0.84375) * 256/2pi
328 { 29.287769007f, 0.710057351f}, // Atan(0.87500) * 256/2pi
329 { 29.997826358f, 0.688317453f}, // Atan(0.90625) * 256/2pi
330 { 30.686143811f, 0.667185647f}, // Atan(0.93750) * 256/2pi
331 { 31.353329458f, 0.646670542f}, // Atan(0.96875) * 256/2pi
332 { 32.000000000f, 0.626776175f}, // Atan(1.00000) * 256/2pi
333 };
334
335
336
337
338
339
340 /*!--------------------------------------------------------------------------*
341 Name: AtanFIdx_
342
343 @brief 逆正接をテーブル引きで求めます。
344
345 @param[in] x 逆正接を求める値。
346 0 <= x <= 1 でなければなりません。
347
348 @return atan(x) の値。
349 ただし360°/256 を1とする単位です。
350 *---------------------------------------------------------------------------*/
AtanFIdx_(f32 x)351 f32 AtanFIdx_(f32 x)
352 {
353 u16 idx;
354 f32 val;
355 f32 r;
356
357 // 0 <= x <= 1 でなければならない
358 x *= 32.f;
359 idx = F32ToU16(x);
360 r = x - U16ToF32(idx);
361
362 val = sArcTanTbl[idx].atan_val + r * sArcTanTbl[idx].atan_delta;
363
364 return val;
365 }
366
367
368 } // end of anonymous namespace
369
370
371
372 /*!--------------------------------------------------------------------------*
373 Name: SinFIdx
374
375 @brief 正弦の値を求めます
376
377 @param[in] fidx 1 円周を 256.0 とする角度
378
379 @return fidx に対する正弦の値を返します。
380 *---------------------------------------------------------------------------*/
SinFIdx(f32 fidx)381 f32 SinFIdx(f32 fidx)
382 {
383 f32 abs_fidx;
384 f32 val;
385 u16 idx;
386 f32 r;
387
388 NN_FLOAT_TASSERT_(fidx);
389
390 abs_fidx = FAbs(fidx);
391 while( abs_fidx >= 65536.0f )
392 {
393 abs_fidx -= 65536.0f;
394 }
395
396 idx = F32ToU16(abs_fidx);
397 r = abs_fidx - U16ToF32(idx);
398 idx &= 0xff;
399
400 val = internal::gSinCosTbl[idx].sin_val + r * internal::gSinCosTbl[idx].sin_delta;
401
402 return (fidx < 0.0f) ? -val: val;
403 }
404
405
406 /*!--------------------------------------------------------------------------*
407 @brief 正弦の値を求めます。
408
409 @param[in] idx 1 円周を 65536 とする角度
410
411 @return idx に対する正弦の値を返します。
412 *---------------------------------------------------------------------------*/
SinIdx(u16 idx)413 f32 SinIdx(u16 idx)
414 {
415 u16 i = idx >> 8;
416 u16 d = idx & 0xff;
417 f32 val = internal::gSinCosTbl[i].sin_val + U16ToF32(d) * (1.f / 256.f) * internal::gSinCosTbl[i].sin_delta;
418
419 val = (idx >> 31) ? -val : val;
420
421 return val;
422 }
423
424
425 /*!--------------------------------------------------------------------------*
426 Name: CosFIdx
427
428 @brief 余弦の値を求めます
429
430 @param[in] fidx 1 円周を 256.0 とする角度
431
432 @return fidx に対する余弦の値を返します。
433 *---------------------------------------------------------------------------*/
CosFIdx(f32 fidx)434 f32 CosFIdx(f32 fidx)
435 {
436 u16 idx;
437 f32 r;
438
439 NN_FLOAT_TASSERT_(fidx);
440
441 fidx = FAbs(fidx);
442 while( fidx >= 65536.0f )
443 {
444 fidx -= 65536.0f;
445 }
446
447 idx = F32ToU16(fidx);
448 r = fidx - U16ToF32(idx);
449 idx &= 0xff;
450
451 return internal::gSinCosTbl[idx].cos_val + r * internal::gSinCosTbl[idx].cos_delta;
452 }
453
454
455 /*!--------------------------------------------------------------------------*
456 @brief 余弦の値を求めます。
457
458 @param[in] idx 1 円周を 65536 とする角度
459
460 @return idx に対する余弦の値を返します。
461 *---------------------------------------------------------------------------*/
CosIdx(u16 idx)462 f32 CosIdx(u16 idx)
463 {
464 u16 i = idx >> 8;
465 u16 d = idx & 0xff;
466 return internal::gSinCosTbl[i].cos_val + U16ToF32(d) * (1.f / 256.f) * internal::gSinCosTbl[i].cos_delta;
467 }
468
469
470 /*!--------------------------------------------------------------------------*
471 Name: SinCosFIdx
472
473 @brief 正弦と余弦の値を求めます。
474
475 @param[out] pSin 正弦の値を格納するバッファへのポインタ
476 @param[out] pCos 余弦の値を格納するバッファへのポインタ
477 @param[in] fidx 1 円周を 256.0 とする角度
478
479 @return なし
480 *---------------------------------------------------------------------------*/
481 void
SinCosFIdx(f32 * pSin,f32 * pCos,f32 fidx)482 SinCosFIdx(f32* pSin, f32* pCos, f32 fidx)
483 {
484 NN_FLOAT_TASSERT_(fidx);
485
486 u16 idx;
487 f32 abs_fidx;
488 f32 r;
489 f32 sVal, cVal;
490
491 abs_fidx = FAbs(fidx);
492 while( abs_fidx >= 65536.0f )
493 {
494 abs_fidx -= 65536.0f;
495 }
496
497 idx = F32ToU16(abs_fidx);
498 r = abs_fidx - U16ToF32(idx);
499 idx &= 0xff;
500
501 sVal = internal::gSinCosTbl[idx].sin_val + r * internal::gSinCosTbl[idx].sin_delta;
502 cVal = internal::gSinCosTbl[idx].cos_val + r * internal::gSinCosTbl[idx].cos_delta;
503
504 *pSin = (fidx < 0.0f) ? -sVal : sVal;
505 *pCos = cVal;
506 }
507
508
509 /*!--------------------------------------------------------------------------*
510 @brief 正弦と余弦の値を求めます。
511
512 @param[out] s 正弦の値を格納するバッファへのポインタ
513 @param[out] c 余弦の値を格納するバッファへのポインタ
514 @param[in] idx 1 円周を 65536 とする角度
515
516 @return なし
517 *---------------------------------------------------------------------------*/
SinCosIdx(f32 * pSin,f32 * pCos,u16 idx)518 void SinCosIdx(f32* pSin, f32* pCos, u16 idx)
519 {
520 u16 i = idx >> 8;
521 u16 d = idx & 0xff;
522 f32 fd = U16ToF32(d) * (1.f / 256.f);
523 f32 sVal = internal::gSinCosTbl[i].sin_val + fd * internal::gSinCosTbl[i].sin_delta;
524 f32 cVal = internal::gSinCosTbl[i].cos_val + fd * internal::gSinCosTbl[i].cos_delta;
525
526 *pSin = (idx >> 31) ? -sVal : sVal;
527 *pCos = cVal;
528 }
529
530
531
532 /*
533 -8 から 8 までを両端を含んで2^16分割し、各サンプル点において誤差を計測
534 sExpTbl[32]の場合 std に対する最大相対誤差 0.0325 % 平均相対誤差 0.00391 %
535 sExpTbl[128]の場合 std に対する最大相対誤差 0.00203 % 平均相対誤差 0.000245 %
536 */
537
538 /*!--------------------------------------------------------------------------*
539 Name: AtanFIdx
540
541 @brief 逆正接をテーブル引きで求めます。
542
543 @param[in] x 逆正接を求める値
544
545 @return 1 円周を 256.0 とする角度で逆正接の値を返します。
546 *---------------------------------------------------------------------------*/
AtanFIdx(f32 x)547 f32 AtanFIdx(f32 x)
548 {
549 if( x >= 0.f )
550 {
551 if( x > 1.f )
552 {
553 // 1 < x
554 return 64.f - AtanFIdx_(1.f/x);
555 }
556 else
557 {
558 // 0 <= x <= 1
559 return AtanFIdx_(x);
560 }
561 }
562 else
563 {
564 if( x < -1.f )
565 {
566 // x < -1
567 return -64.f + AtanFIdx_(-1.f/x);
568 }
569 else
570 {
571 // -1 <= x < 0
572 return - AtanFIdx_(-x);
573 }
574 }
575
576 }
577
578
579 /*!--------------------------------------------------------------------------*
580 Name: AtanFIdx
581
582 @brief 逆正接の値を求めます。
583
584 @param[in] y 正接の値の分子
585 @param[in] x 正接の値の分母
586
587 @return y/x の逆正接の値を 256.0 を 1 円周とする単位で返します
588 *---------------------------------------------------------------------------*/
Atan2FIdx(f32 y,f32 x)589 f32 Atan2FIdx(f32 y, f32 x)
590 {
591 f32 a;
592 f32 b;
593 f32 c;
594 bool minus;
595
596 if( x == 0.f && y == 0.f )
597 {
598 return 0.f;
599 }
600
601 if( x >= 0.f )
602 {
603 if( y >= 0.f )
604 {
605 if( x >= y )
606 {
607 // 1
608 a = x;
609 b = y;
610 c = 0.f;
611 minus = false;
612 }
613 else
614 {
615 // 2
616 a = y;
617 b = x;
618 c = 64.f;
619 minus = true;
620 }
621 }
622 else
623 {
624 if( x >= -y )
625 {
626 // -1
627 a = x;
628 b = -y;
629 c = 0.f;
630 minus = true;
631 }
632 else
633 {
634 // -2
635 a = -y;
636 b = x;
637 c = - 64.f;
638 minus = false;
639 }
640 }
641 }
642 else
643 {
644 if( y >= 0.f )
645 {
646 if( -x >= y )
647 {
648 // 4
649 a = -x;
650 b = y;
651 c = 128.f;
652 minus = true;
653 }
654 else
655 {
656 // 3
657 a = y;
658 b = -x;
659 c = 64.f;
660 minus = false;
661 }
662 }
663 else
664 {
665 if( -x >= -y )
666 {
667 // -4
668 a = -x;
669 b = -y;
670 c = - 128.f;
671 minus = false;
672 }
673 else
674 {
675 // -3
676 a = -y;
677 b = -x;
678 c = - 64.f;
679 minus = true;
680 }
681 }
682 }
683
684 return minus ?
685 c - AtanFIdx_(b/a):
686 c + AtanFIdx_(b/a);
687 }
688
689
690
691 /*!--------------------------------------------------------------------------*
692 Name: AtanIdx
693
694 @brief 逆正接をテーブル引きで求めます。
695
696 @param[in] x 逆正接を求める値
697
698 @return x に対する逆正接の値を 65536 を 1 円周とする単位で返します
699 *---------------------------------------------------------------------------*/
700 // 0°~ 90°と 270°~ 360°の範囲のインデックスを返します
AtanIdx(f32 x)701 u16 AtanIdx(f32 x)
702 {
703 f32 fidx = 0.f;
704 if( x >= 0.f )
705 {
706 if( x > 1.f )
707 {
708 // 1 < x
709 fidx = 64.f - AtanFIdx_(1.f/x);
710 }
711 else
712 {
713 // 0 <= x <= 1
714 fidx = AtanFIdx_(x);
715 }
716 }
717 else
718 {
719 if( x < -1.f )
720 {
721 // x < -1
722 fidx = 256.f - 64.f + AtanFIdx_(-1.f/x);
723 }
724 else
725 {
726 // -1 <= x < 0
727 fidx = 256.f - AtanFIdx_(-x);
728 }
729 }
730 return F32ToU16(fidx * 256.f);
731 }
732
733
734
735 /*!--------------------------------------------------------------------------*
736 Name: Atan2Idx
737
738 @brief 逆正接をテーブル引きで求めます。
739
740 @param[in] y 正接の値の分子
741 @param[in] x 正接の値の分母
742
743 @return y/x の逆正接の値を 65536 を 1 円周とする単位で返します
744 *---------------------------------------------------------------------------*/
745 // 0°~ 360°の範囲のインデックスを返します
Atan2Idx(f32 y,f32 x)746 u16 Atan2Idx(f32 y, f32 x)
747 {
748 f32 a;
749 f32 b;
750 f32 c;
751 bool minus;
752
753 if( x == 0.f && y == 0.f )
754 {
755 return 0;
756 }
757
758 if( x >= 0.f )
759 {
760 if( y >= 0.f )
761 {
762 if( x >= y )
763 {
764 // 1
765 a = x;
766 b = y;
767 c = 0.f;
768 minus = false;
769 }
770 else
771 {
772 // 2
773 a = y;
774 b = x;
775 c = 64.f;
776 minus = true;
777 }
778 }
779 else
780 {
781 if( x >= -y )
782 {
783 // -1
784 a = x;
785 b = -y;
786 c = 256.f;
787 minus = true;
788 }
789 else
790 {
791 // -2
792 a = -y;
793 b = x;
794 c = 192.f;
795 minus = false;
796 }
797 }
798 }
799 else
800 {
801 if( y >= 0.f )
802 {
803 if( -x >= y )
804 {
805 // 4
806 a = -x;
807 b = y;
808 c = 128.f;
809 minus = true;
810 }
811 else
812 {
813 // 3
814 a = y;
815 b = -x;
816 c = 64.f;
817 minus = false;
818 }
819 }
820 else
821 {
822 if( -x >= -y )
823 {
824 // -4
825 a = -x;
826 b = -y;
827 c = 128.f;
828 minus = false;
829 }
830 else
831 {
832 // -3
833 a = -y;
834 b = -x;
835 c = 192.f;
836 minus = true;
837 }
838 }
839 }
840
841 return F32ToU16((minus ? c - AtanFIdx_(b/a) : c + AtanFIdx_(b/a)) * 256.f);
842 }
843
844
845
846 }} // nw::math
847