diff --git a/docs/signatures.md b/docs/signatures.md index f5daf3c..b2fe262 100644 --- a/docs/signatures.md +++ b/docs/signatures.md @@ -6,6 +6,12 @@ GLMS_AST_TYPE_VEC3 unit(GLMS_AST_TYPE_VEC3) ``` +### ceil +``` +GLMS_AST_TYPE_NUMBER ceil(GLMS_AST_TYPE_NUMBER) + +``` + ### cantor ``` GLMS_AST_TYPE_NUMBER cantor(GLMS_AST_TYPE_NUMBER, GLMS_AST_TYPE_NUMBER) @@ -149,6 +155,18 @@ GLMS_AST_TYPE_NUMBER cos(GLMS_AST_TYPE_NUMBER) ``` +### floor +``` +GLMS_AST_TYPE_NUMBER floor(GLMS_AST_TYPE_NUMBER) + +``` + +### round +``` +GLMS_AST_TYPE_NUMBER round(GLMS_AST_TYPE_NUMBER) + +``` + ### quatFor ``` GLMS_AST_TYPE_VEC4 quatFor(GLMS_AST_TYPE_VEC4 dir, GLMS_AST_TYPE_VEC4 up) diff --git a/include/glms/version.h b/include/glms/version.h index 99cfca7..6174db4 100644 --- a/include/glms/version.h +++ b/include/glms/version.h @@ -3,8 +3,8 @@ #define GLMS_VERSION_MAJOR 0 #define GLMS_VERSION_MINOR 0 -#define GLMS_VERSION_PATCH 3 +#define GLMS_VERSION_PATCH 4 -#define GLMS_VERSION_STRING "0.0.3" +#define GLMS_VERSION_STRING "0.0.4" #endif diff --git a/src/builtin.c b/src/builtin.c index 5a38e7d..63f790c 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -285,6 +285,39 @@ int glms_fptr_abs(GLMSEval* eval, GLMSAST* ast, GLMSASTBuffer* args, return 1; } +int glms_fptr_floor(GLMSEval* eval, GLMSAST* ast, GLMSASTBuffer* args, + GLMSStack* stack, GLMSAST* out) { + if (args->length <= 0) return 0; + + GLMSAST value = glms_eval(eval, args->items[0], stack); + + *out = (GLMSAST){.type = GLMS_AST_TYPE_NUMBER, .as.number.value = floorf(glms_ast_number(value))}; + + return 1; +} + +int glms_fptr_ceil(GLMSEval* eval, GLMSAST* ast, GLMSASTBuffer* args, + GLMSStack* stack, GLMSAST* out) { + if (args->length <= 0) return 0; + + GLMSAST value = glms_eval(eval, args->items[0], stack); + + *out = (GLMSAST){.type = GLMS_AST_TYPE_NUMBER, .as.number.value = ceilf(glms_ast_number(value))}; + + return 1; +} + +int glms_fptr_round(GLMSEval* eval, GLMSAST* ast, GLMSASTBuffer* args, + GLMSStack* stack, GLMSAST* out) { + if (args->length <= 0) return 0; + + GLMSAST value = glms_eval(eval, args->items[0], stack); + + *out = (GLMSAST){.type = GLMS_AST_TYPE_NUMBER, .as.number.value = roundf(glms_ast_number(value))}; + + return 1; +} + int glms_fptr_sin(GLMSEval* eval, GLMSAST* ast, GLMSASTBuffer* args, GLMSStack* stack, GLMSAST* out) { if (args->length <= 0) return 0; @@ -826,6 +859,30 @@ void glms_builtin_init(GLMSEnv* env) { .args = (GLMSType[]){(GLMSType){GLMS_AST_TYPE_NUMBER}}, .args_length = 1}); + glms_env_register_function(env, "floor", glms_fptr_floor); + glms_env_register_function_signature( + env, 0, "floor", + (GLMSFunctionSignature){ + .return_type = (GLMSType){GLMS_AST_TYPE_NUMBER}, + .args = (GLMSType[]){(GLMSType){GLMS_AST_TYPE_NUMBER}}, + .args_length = 1}); + + glms_env_register_function(env, "ceil", glms_fptr_ceil); + glms_env_register_function_signature( + env, 0, "ceil", + (GLMSFunctionSignature){ + .return_type = (GLMSType){GLMS_AST_TYPE_NUMBER}, + .args = (GLMSType[]){(GLMSType){GLMS_AST_TYPE_NUMBER}}, + .args_length = 1}); + + glms_env_register_function(env, "round", glms_fptr_round); + glms_env_register_function_signature( + env, 0, "round", + (GLMSFunctionSignature){ + .return_type = (GLMSType){GLMS_AST_TYPE_NUMBER}, + .args = (GLMSType[]){(GLMSType){GLMS_AST_TYPE_NUMBER}}, + .args_length = 1}); + glms_env_register_function(env, "atan", glms_fptr_atan); glms_env_register_function_signature( env, 0, "atan",