commit 1d08d368d57a1499c9d2e7c4cafb04d632bada4d Author: clfreville2 Date: Fri Oct 14 08:39:42 2022 +0200 Ajoute le paquet mths diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57c3dad --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# IDEs +.vscode +.idea +*.swp + +# Executables +test* +!test/ +!test*.c diff --git a/mths/Makefile b/mths/Makefile new file mode 100644 index 0000000..14598da --- /dev/null +++ b/mths/Makefile @@ -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 diff --git a/mths/src/mths.h b/mths/src/mths.h new file mode 100644 index 0000000..3b0b0c3 --- /dev/null +++ b/mths/src/mths.h @@ -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) diff --git a/mths/test/testMths.c b/mths/test/testMths.c new file mode 100644 index 0000000..f69b696 --- /dev/null +++ b/mths/test/testMths.c @@ -0,0 +1,23 @@ +#include "mths.h" + +#include +#include + +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; +}