Add swap and absolute utilities
This commit is contained in:
parent
e39ee53b86
commit
52d79817ad
10
src/utils.c
Normal file
10
src/utils.c
Normal 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
14
src/utils.h
Normal 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
|
Loading…
Reference in New Issue
Block a user