Add absolute, radians and degrees math utilities

This commit is contained in:
Abdelrahman Said 2024-01-24 23:42:40 +00:00
parent 8275fce9c6
commit c70f252349
2 changed files with 8 additions and 0 deletions

View File

@ -4,8 +4,11 @@
#include "aliases/aliases.h"
#define square(x) (x * x)
#define absolute(x) (x < 0.0 ? x * -1.0 : x)
i32 min(i32 a, i32 b);
i32 max(i32 a, i32 b);
f64 radians(f64 degrees);
f64 degrees(f64 radians);
#endif // !MATH_UTILS_H

View File

@ -1,5 +1,10 @@
#include "math_utils.h"
#include <math.h>
i32 min(i32 a, i32 b) { return a <= b ? a : b; }
i32 max(i32 a, i32 b) { return a >= b ? a : b; }
f64 radians(f64 degrees) { return degrees * M_PI / 180.0; }
f64 degrees(f64 radians) { return radians * 180.0 / M_PI; }