From 09c2773a7a67b020833d5fabd2746a823430b271 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Thu, 15 Jan 2026 15:07:40 +0000 Subject: [PATCH 1/2] Update Makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 2a24a36..00c809c 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,7 @@ install: both cp $(EXECUTABLE) $(DESTDIR)$(PREFIX)/bin/ cp $(SHARED_LIB) $(DESTDIR)$(PREFIX)/lib/ cp $(HEADERS) $(DESTDIR)$(PREFIX)/include/ + echo "$(DESTDIR)$(PREFIX)/lib" | tee $(DESTDIR)/etc/ld.so.conf.d/cground.conf ldconfig # Debug: print variables From f2968f74b324d3d4a680de6b5610c5caf3d16a78 Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Mon, 19 Jan 2026 20:32:29 +1100 Subject: [PATCH 2/2] added math library --- libs/math/math.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 libs/math/math.c diff --git a/libs/math/math.c b/libs/math/math.c new file mode 100644 index 0000000..b48744c --- /dev/null +++ b/libs/math/math.c @@ -0,0 +1,77 @@ +#include +#include + +GroundValue ground_sin(GroundScope* scope, List args) { + return groundCreateValue( + DOUBLE, + sin(args.values[0].data.doubleVal) + ); +} +GroundValue ground_cos(GroundScope* scope, List args) { + return groundCreateValue( + DOUBLE, + cos(args.values[0].data.doubleVal) + ); +} +GroundValue ground_tan(GroundScope* scope, List args) { + return groundCreateValue( + DOUBLE, + tan(args.values[0].data.doubleVal) + ); +} + +GroundValue rad_to_deg(GroundScope* scope, List args) { + double radians = args.values[0].data.doubleVal; + + return groundCreateValue( + DOUBLE, + radians * (180.0 / M_PI) + ); +} +GroundValue deg_to_rad(GroundScope* scope, List args) { + double deg = args.values[0].data.doubleVal; + + return groundCreateValue( + DOUBLE, + deg * (M_PI / 180.0) + ); +} + +GroundValue ground_modulos(GroundScope* scope, List args) { + return groundCreateValue( + DOUBLE, + fmod(args.values[0].data.doubleVal, args.values[1].data.doubleVal) + ); +} +GroundValue ground_pow(GroundScope* scope, List args) { + return groundCreateValue( + DOUBLE, + pow(args.values[0].data.doubleVal, args.values[1].data.doubleVal) + ); +} +GroundValue ground_sqrt(GroundScope* scope, List args) { + double value = args.values[0].data.doubleVal; + + if (value < 0) { + ERROR("Can't get square root of number less than 0.", "InvalidMath"); + } + + return groundCreateValue( + DOUBLE, + sqrt(value) + ); +} + +void ground_init(GroundScope* scope) { + groundAddNativeFunction(scope, "math_Sin", ground_sin, DOUBLE, 1, DOUBLE, "radians"); + groundAddNativeFunction(scope, "math_Cos", ground_cos, DOUBLE, 1, DOUBLE, "radians"); + groundAddNativeFunction(scope, "math_Tan", ground_tan, DOUBLE, 1, DOUBLE, "radians"); + + groundAddNativeFunction(scope, "math_DegreesToRadians", deg_to_rad, DOUBLE, 1, DOUBLE, "degrees"); + groundAddNativeFunction(scope, "math_RadiansToDegrees", rad_to_deg, DOUBLE, 1, DOUBLE, "radians"); + + groundAddNativeFunction(scope, "math_Modulos", ground_modulos, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); + groundAddNativeFunction(scope, "math_Pow", ground_pow, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); + + groundAddNativeFunction(scope, "math_Sqrt", ground_sqrt, DOUBLE, 1, DOUBLE, "number"); +} \ No newline at end of file