@@ -58,32 +58,31 @@ namespace detail
5858
5959 return detail::cos_52s(two_pi<T>() - angle);
6060 */
61- /*
62- approximated using "cos(sqrt(x))"
63- interval [0, pi/2]
64- */
61+
62+ // approximated using "cos(sqrt(x))"
63+ // interval [0, pi/2]
6564 T mx, x2, out, C0, C1, C2, C3, C4, C5, C6;
6665 bool sign, flip;
6766 int q;
68- /* coefficients */
67+ // coefficients
6968 C0 = T ( 2.0254959785478004e-09 );
7069 C1 = T (-2.7543954056392956e-07 );
7170 C2 = T ( 2.4801444520278038e-05 );
7271 C3 = T (-1.3888888105171723e-03 );
7372 C4 = T ( 0.4166666664617346e-01 );
7473 C5 = T (-4.9999999999799011e-01 );
7574 C6 = T ( 0.9999999999999678e-00 );
76- /* sign handle */
75+ // sign handle
7776 mx = x < T (0.0 ) ? -x : x;
78- /* remainder */
77+ // remainder
7978 mx = mx - ::trunc (mx * T (0.1591549 )) * T (6.283185307 );
80- /* range reduction*/
79+ // range reduction
8180 q = ((int )(mx * T (0.6366197 ))+1 );
8281 flip = (q == 2 || q == 4 );
8382 sign = (q == 2 || q == 3 );
8483 mx = mx - (T (1.57079632 ) * T (q-1 ));
8584 mx = flip ? (mx - T (1.57079632 )) : mx;
86- /* range reduction */
85+ // polynomial
8786 x2 = mx * mx;
8887 out = ((((((C0 * x2 + C1) * x2 + C2) * x2 + C3) * x2 + C4) * x2 + C5) * x2 + C6);
8988 out = sign ? -out : out;
@@ -101,33 +100,33 @@ namespace detail
101100 GLM_FUNC_QUALIFIER T fastSin (T x)
102101 {
103102 // return fastCos<T>(half_pi<T>() - x);
104- /*
105- this function is approximated using this formula : (sin(sqrt(x))-sqrt(x)) / (x * sqrt(x))
106- interval [0, pi/2]
107- sin(x) ≈ x * x3 * sin_poly(x2)
108- where : sin_poly (x) = (((C0 * x + C1) * x + C2) * x + C3 )
109- for -x = -sin(abs(x) )
110- */
103+
104+
105+ // this function is approximated using this formula : (sin(sqrt(x))-sqrt(x)) / (x * sqrt(x))
106+ // interval [0, pi/2]
107+ // sin (x) ≈ x * x3 * sin_poly(x2 )
108+ // where : sin_poly(x) = (((C0 * x + C1) * x + C2) * x + C3 )
109+ // for -x = -sin(abs(x))
111110 T mx, x2, out, C0, C1, C2, C3;
112111 bool sign, flip;
113112 int q;
114- /* coefficients */
113+ // coefficients
115114 C0 = T ( 2.678156924342569e-06 );
116115 C1 = T (-1.983369323468157e-04 );
117116 C2 = T ( 8.333309602749911e-03 );
118117 C3 = T (-1.666666655047327e-01 );
119118 mx = x;
120119 sign = mx < T (0.0 );
121120 mx = sign ? -mx : mx;
122- /* remainder */
121+ // remainder
123122 mx = mx - ::trunc (mx * T (0.1591549 )) * T (6.283185307 );
124- /* range reduction */
123+ // range reduction
125124 q = ((int )(mx * T (0.6366197 ))+1 );
126125 flip = (q == 2 || q == 4 );
127126 sign ^= q > 2 ;
128127 mx = mx - (T (1.57079632 ) * T (q-1 ));
129128 mx = flip ? (T (1.57079632 ) - mx) : mx;
130- /* polynomial */
129+ // polynomial
131130 x2 = mx * mx;
132131 out = mx + (x2 * mx) * (((C0 * x2 + C1) * x2 + C2) * x2 + C3);
133132 out = sign ? -out : out;
@@ -144,11 +143,9 @@ namespace detail
144143 template <typename T>
145144 GLM_FUNC_QUALIFIER T fastTan (T x)
146145 {
147- /*
148- calculated using "sin(x)/cos(x)"
149- this is much more efficient because it only perform single
150- range reduction and remainder operation, unlike separate sin and cos
151- */
146+ // calculated using "sin(x)/cos(x)"
147+ // this is much more efficient because it only perform single
148+ // range reduction and remainder operation, unlike separate sin and cos
152149 T mx, sx, cx, out, x2, S0, S1, S2, S3, C0, C1, C2, C3, C4, C5, C6;
153150 bool sign, flip;
154151 int q;
@@ -168,15 +165,15 @@ namespace detail
168165 mx = x;
169166 sign = mx < T (0.0 );
170167 mx = sign ? -mx : mx;
171- /* remainder */
168+ // remainder
172169 mx = mx - ::trunc (mx * T (0.1591549 )) * T (6.283185307 );
173- /* range reduction */
170+ // range reduction
174171 q = ((int )(mx * T (0.6366197 ))+1 );
175172 flip = (q == 2 || q == 4 );
176173 sign ^= flip;
177174 mx = mx - (T (1.57079632 ) * T (q-1 ));
178175 mx = flip ? (T (1.57079632 ) - mx) : mx;
179- /* polynomial */
176+ // polynomial
180177 x2 = mx * mx;
181178 sx = mx + (x2 * mx) * (((S0 * x2 + S1) * x2 + S2) * x2 + S3);
182179 cx = ((((((C0 * x2 + C1) * x2 + C2) * x2 + C3) * x2 + C4) * x2 + C5) * x2 + C6);
@@ -195,15 +192,13 @@ namespace detail
195192 template <typename T>
196193 GLM_FUNC_QUALIFIER T fastAsin (T x)
197194 {
198- /*
199- approximated using this formula "(atan(sqrt(x))-sqrt(x)) / (x * sqrt(x))"
200- for x <= 0.5 asin(x) = x + x^3 + asin_poly(x^2)
201- for x > 0.5 asin(x) = asin(sqrt((1 - x) / 2))
202- */
195+ // approximated using this formula "(asin(sqrt(x))-sqrt(x)) / (x * sqrt(x))"
196+ // for x <= 0.5 asin(x) = x + x^3 + asin_poly(x^2)
197+ // for x > 0.5 asin(x) = asin(sqrt((1 - x) / 2))
203198 // TODO : fix glm::fastSqrt, it kills accuracy
204199 T mx, x2, out, C0, C1, C2, C3, C4;
205200 bool sign, more_x;
206- /* coefficients interval [0, 0.5] */
201+ // coefficients interval [0, 0.5]
207202 C0 = T (0.038328305e-00 );
208203 C1 = T (0.026433362e-00 );
209204 C2 = T (0.045020215e-00 );
@@ -263,16 +258,14 @@ namespace detail
263258 template <typename T>
264259 GLM_FUNC_QUALIFIER T fastAtan (T x)
265260 {
266- /*
267- approximated using this formula "(atan(sqrt(x))-sqrt(x)) / (x * sqrt(x))"
268- interval [0, 0.5]
269- for x <= 0.5 atan(x) = x*C0 + x2*C1 + x3*C2...
270- for x > 0.5 && x < 1.0 atan(x) = atan((x - 1) / (1 + x)) + pi/4
261+ // approximated using this formula "(atan(sqrt(x))-sqrt(x)) / (x * sqrt(x))"
262+ // interval [0, 0.5]
263+ // for x <= 0.5 atan(x) = x*C0 + x2*C1 + x3*C2...
264+ // for x > 0.5 && x < 1.0 atan(x) = atan((x - 1) / (1 + x)) + pi/4
271265
272- for x > 1.0 -> inf atan(x) = asin(x / sqrt(1 + x*x))
273- better accuracy:
274- for x > 1.0 -> inf atan(x) = pi_half - atan(1.0 / x)
275- */
266+ // for x > 1.0 -> inf atan(x) = asin(x / sqrt(1 + x*x))
267+ // better accuracy:
268+ // for x > 1.0 -> inf atan(x) = pi_half - atan(1.0 / x)
276269 T mx, x2, out, C0, C1, C2, C3, C4;
277270 bool low, high, sign;
278271 C0 = T (-0.037163095549048668 );
0 commit comments