Add swap and absolute utilities

This commit is contained in:
Abdelrahman Said 2024-07-20 17:21:50 +01:00
parent e39ee53b86
commit 52d79817ad
2 changed files with 24 additions and 0 deletions

10
src/utils.c Normal file
View File

@ -0,0 +1,10 @@
#include "utils.h"
#include "aliases.h"
i64 absolute(i64 value) {
if (value >= 0) {
return value;
}
return value * -1;
}

14
src/utils.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef UTILS_H
#define UTILS_H
#include "aliases.h"
#define swap(T, v0, v1) \
do { \
T tmp = v0; \
v0 = v1; \
v1 = tmp; \
} while (0)
i64 absolute(i64 value);
#endif // UTILS_H