20 #ifndef INCLUDE_WYKOBI_MATH
21 #define INCLUDE_WYKOBI_MATH
27 #define WYKOBI_DOUBLE_PRECISION
29 #ifdef WYKOBI_SINGLE_PRECISION
33 #ifdef WYKOBI_DOUBLE_PRECISION
37 #ifdef WYKOBI_EXTENDED_PRECISION
38 typedef long double Float;
42 static const Float Epsilon_High = 1.0E-16;
43 static const Float Epsilon_Medium = 1.0E-10;
44 static const Float Epsilon_Low = 1.0E-07;
45 static const Float Epsilon = Epsilon_Medium;
49 static const std::size_t RANDOM_RESOLUTION_INT = 1000000000;
50 static const double RANDOM_RESOLUTION_FLT = RANDOM_RESOLUTION_INT * 1.0;
53 static const Float PI =
Float(3.141592653589793238462643383279500);
54 static const Float PI2 =
Float(6.283185307179586476925286766559000);
55 static const Float PIDiv180 =
Float(0.017453292519943295769236907684886);
56 static const Float _180DivPI =
Float(57.295779513082320876798154814105000);
59 inline T
sqr(
const T& val);
61 inline T
sqrt(
const T& val);
63 inline T
abs(
const T& value);
65 inline T
max(
const T& value1,
const T& value2);
67 inline T
min(
const T& value1,
const T& value2);
69 inline T
max(
const T& value1,
const T& value2,
const T& value3);
71 inline T
min(
const T& value1,
const T& value2,
const T& value3);
76 inline T
sin(
const T& value);
78 inline T
cos(
const T& value);
80 inline T
tan(
const T& value);
82 inline T
asin(
const T& value);
84 inline T
acos(
const T& value);
86 inline T
atan(
const T& value);
95 inline T
clamp(
const T& value,
const T& low,
const T& high);
98 inline T
sqr(
const T& val) {
102 template <
typename T>
107 template <
typename T>
108 inline T
abs(
const T& value) {
112 template <
typename T>
113 inline T
max(
const T& value1,
const T& value2) {
114 return std::max<T>(value1, value2);
117 template <
typename T>
118 inline T
min(
const T& value1,
const T& value2) {
119 return std::min<T>(value1, value2);
122 template <
typename T>
123 inline T
max(
const T& value1,
const T& value2,
const T& value3) {
124 return max(value1,
max(value2, value3));
127 template <
typename T>
128 inline T
min(
const T& value1,
const T& value2,
const T& value3) {
129 return min(value1,
min(value2, value3));
132 template <
typename T>
137 template <
typename T>
138 inline T
sin(
const T& value) {
142 template <
typename T>
143 inline T
cos(
const T& value) {
147 template <
typename T>
148 inline T
tan(
const T& value) {
152 template <
typename T>
153 inline T
asin(
const T& value) {
157 template <
typename T>
158 inline T
acos(
const T& value) {
162 template <
typename T>
163 inline T
atan(
const T& value) {
167 template <
typename T>
169 T final_sign = T(1.0);
171 if ((angle <= T(180.0)) && (angle > 90.0)) {
172 angle = T(180.0) - angle;
174 }
else if ((angle <= T(270.0)) && (angle > T(180.0))) {
175 angle = angle - T(180.0);
176 final_sign = T(-1.0);
177 }
else if ((angle <= T(360.0)) && (angle > T(270.0))) {
178 angle = T(360.0) - angle;
179 final_sign = T(-1.0);
182 angle *= T(PI / 180.0);
183 T asqr = angle * angle;
184 T result = T(-2.39e-08);
186 result += T(2.7526e-06);
188 result -= T(1.98409e-04);
190 result += T(8.3333315e-03);
192 result -= T(1.666666664e-01);
197 return result * final_sign;
200 template <
typename T>
202 T final_sign = T(1.0);
204 if ((angle <= T(180.0)) && (angle > 90.0)) {
205 angle = T(180.0) - angle;
206 final_sign = T(-1.0);
207 }
else if ((angle <= T(270.0)) && (angle > T(180.0))) {
208 angle = angle - T(180.0);
209 final_sign = T(-1.0);
210 }
else if ((angle <= T(360.0)) && (angle > T(270.0))) {
211 angle = T(360.0) - angle;
215 angle *= T(PI / 180.0);
216 T asqr = angle * angle;
217 T result = T(-2.605e-07);
219 result += T(2.47609e-05);
221 result -= T(1.3888397e-03);
223 result += T(4.16666418e-02);
225 result -= T(4.999999963e-01);
229 return result * final_sign;
232 template <
typename T>
234 T final_sign = T(1.0);
236 if ((angle <= T(180.0)) && (angle > 90.0)) {
237 angle = T(180.0) - angle;
238 final_sign = T(-1.0);
239 }
else if ((angle <= T(270.0)) && (angle > T(180.0))) {
240 angle = angle - T(180.0);
242 }
else if ((angle <= T(360.0)) && (angle > T(270.0))) {
243 angle = T(360.0) - angle;
244 final_sign = T(-1.0);
247 angle *= T(PI / 180.0);
248 T asqr = angle * angle;
249 T result = T(9.5168091e-03);
251 result += T(2.900525e-03);
253 result += T(2.45650893e-02);
255 result += T(5.33740603e-02);
257 result += T(1.333923995e-01);
259 result += T(3.333314036e-01);
264 return result * final_sign;
267 template <
typename T>
268 inline T
clamp(
const T& value,
const T& low_end,
const T& high_end) {
269 if (value < low_end)
return low_end;
270 if (value > high_end)
return high_end;
Definition: wykobi.hpp:32
T infinity()
Definition: wykobi_math.hpp:133
T acos(const T &value)
Definition: wykobi_math.hpp:158
T approx_tan(T angle)
Definition: wykobi_math.hpp:233
T sin(const T &value)
Definition: wykobi_math.hpp:138
T cos(const T &value)
Definition: wykobi_math.hpp:143
T atan(const T &value)
Definition: wykobi_math.hpp:163
T tan(const T &value)
Definition: wykobi_math.hpp:148
double Float
Definition: wykobi_math.hpp:34
T clamp(const T &value, const T &low, const T &high)
Definition: wykobi_math.hpp:268
T asin(const T &value)
Definition: wykobi_math.hpp:153
T max(const T &value1, const T &value2)
Definition: wykobi_math.hpp:113
T sqrt(const T &val)
Definition: wykobi_math.hpp:103
T sqr(const T &val)
Definition: wykobi_math.hpp:98
T min(const T &value1, const T &value2)
Definition: wykobi_math.hpp:118
T abs(const T &value)
Definition: wykobi_math.hpp:108
T approx_sin(T angle)
Definition: wykobi_math.hpp:168
T approx_cos(T angle)
Definition: wykobi_math.hpp:201