math library #8
1
Makefile
1
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
|
||||
|
||||
77
libs/math/math.c
Normal file
77
libs/math/math.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <groundext.h>
|
||||
#include <math.h>
|
||||
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user