Ajoute le paquet mths

main
Clément FRÉVILLE 3 years ago
commit 1d08d368d5

9
.gitignore vendored

@ -0,0 +1,9 @@
# IDEs
.vscode
.idea
*.swp
# Executables
test*
!test/
!test*.c

@ -0,0 +1,12 @@
all: test
test: testMths
./testMths
testMths: test/testMths.c
gcc -Wall -Isrc/ test/testMths.c -o testMths
clean:
rm -f testMths
.PHONY: all test clean

@ -0,0 +1,8 @@
/** Get the maximum between two numbers */
#define MAX(x, y) ((x > y) ? x : y)
/** Get the minimum between two numbers */
#define MIN(x, y) ((x < y) ? x : y)
/** Linearly interpolate t between two points a and b */
#define LERP(a, b, t) ((b - a) * t + a)

@ -0,0 +1,23 @@
#include "mths.h"
#include <assert.h>
#include <stdio.h>
int main(void) {
assert(MAX(5, 5) == 5);
assert(MAX(7, 2) == 7);
assert(MAX(4, 9) == 9);
assert(MIN(5, 5) == 5);
assert(MIN(7, 2) == 2);
assert(MIN(4, 9) == 4);
assert(LERP(0., 4., 0.) == 0.);
assert(LERP(0., 4., 0.25) == 1.);
assert(LERP(0., 4., 0.5) == 2.);
assert(LERP(0., 4., 0.75) == 3.);
assert(LERP(0., 4., 1.) == 4.);
printf("Success!\n");
return 0;
}
Loading…
Cancel
Save