From c70f252349dfb536074df79450a413b393830ef3 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Wed, 24 Jan 2024 23:42:40 +0000 Subject: [PATCH] Add absolute, radians and degrees math utilities --- include/math_utils.h | 3 +++ src/math_utils.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/math_utils.h b/include/math_utils.h index 0b66576..d5e16d4 100644 --- a/include/math_utils.h +++ b/include/math_utils.h @@ -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 diff --git a/src/math_utils.c b/src/math_utils.c index eb48205..9b8eb41 100644 --- a/src/math_utils.c +++ b/src/math_utils.c @@ -1,5 +1,10 @@ #include "math_utils.h" +#include 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; }