15 static constexpr float PI = 3.141592653589793;
23 static float pow(
float base,
int exponent) {
29 else if (exponent < 0)
42 static float min(
float a,
float b) {
52 static int min(
int a,
int b) {
62 static float max(
float a,
float b) {
72 static int max(
int a,
int b) {
81 static float fabs(
float n) {
82 return n < 0 ? -n : n;
90 static int abs(
int n) {
91 return n < 0 ? -n : n;
99 static float sqrt(
float n) {
100 if (n == 0)
return 0;
104 double epsilon = 0.000001;
106 while (
fabs(x - y) > epsilon) {
119 static float cos(
float angle) {
121 while (angle >= 2 *
PI)
130 return cosine[(int) (0.5 + 500 * angle / (2 *
PI))];
139 return x >= 0 ? 1 : -1;
147 static float sin(
float angle) {
148 return cos(angle -
PI/2);
158 return sign(m) * arctan[
min(
int(
abs(m * (500 / 10)) + 0.5), 499)];
168 static float atan(
float y,
float x) {
176 static constexpr float cosine[500] = {
299 0.037690182669934694,
301 0.012566039883352776,
302 6.123233995736766e-17,
303 -0.012566039883352653,
304 -0.025130095443337407,
305 -0.037690182669934576,
306 -0.05024431817976947,
308 -0.07532680552793262,
312 -0.12533323356430437,
313 -0.13779029068463805,
314 -0.15022558912075715,
315 -0.16263716519488358,
316 -0.17502305897527615,
317 -0.18738131458572482,
320 -0.22427076094938103,
321 -0.23649899702372443,
322 -0.24868988716485463,
323 -0.26084150628989666,
324 -0.27295193551732505,
325 -0.28501926246997605,
326 -0.29704158157703475,
327 -0.30901699437494734,
329 -0.33281954452298657,
331 -0.35641187871325064,
336 -0.41437558099328414,
341 -0.47070393216533263,
342 -0.48175367410171543,
343 -0.49272734154829145,
512 -0.48175367410171527,
513 -0.47070393216533246,
514 -0.45957986062148765,
515 -0.44838321609003196,
517 -0.42577929156507216,
518 -0.41437558099328436,
521 -0.37977909552180183,
523 -0.35641187871325125,
526 -0.32094360980720976,
527 -0.30901699437494756,
529 -0.28501926246997694,
530 -0.27295193551732594,
531 -0.26084150628989755,
535 -0.21200710992205485,
537 -0.18738131458572463,
538 -0.17502305897527595,
539 -0.16263716519488428,
540 -0.15022558912075762,
541 -0.13779029068463852,
543 -0.11285638487348193,
544 -0.10036171485121503,
545 -0.08785119655074321,
546 -0.07532680552793265,
547 -0.06279051952931321,
548 -0.05024431817977017,
549 -0.03769018266993504,
550 -0.025130095443337875,
551 -0.012566039883352897,
552 -1.8369701987210297e-16,
553 0.012566039883352531,
554 0.025130095443337507,
679 static constexpr float arctan[500] = {
681 0.019997333973150535,
682 0.039978687123290044,
A class that provides light-weight mathematical functions.
Definition Math.h:13
static float atan(float m)
get the arc tangent of a ratio if slope approaches infinity
Definition Math.h:157
static float pow(float base, int exponent)
exponentiation
Definition Math.h:23
static int sign(float x)
get the sign of number
Definition Math.h:138
static int max(int a, int b)
get maximum integer value
Definition Math.h:72
static float max(float a, float b)
get maximum float value
Definition Math.h:62
static float atan(float y, float x)
get the arc tangent of the ratio constructed by the y amount and the x amount if x is zero,...
Definition Math.h:168
static float fabs(float n)
get the floating-point absolute value
Definition Math.h:81
static float sqrt(float n)
get the square root of the number
Definition Math.h:99
static constexpr float PI
Definition Math.h:15
static float cos(float angle)
get the cosine of the angle
Definition Math.h:119
static float min(float a, float b)
get minimum float value
Definition Math.h:42
static int abs(int n)
get integer absolute value
Definition Math.h:90
static int min(int a, int b)
get minimum integer value
Definition Math.h:52
static float sin(float angle)
get the sine of the angle
Definition Math.h:147