Skip to content

Commit

Permalink
adds floor() ceil() round()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbekarlsson committed Jan 7, 2023
1 parent 05fde67 commit 8a6513b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions include/glms/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
57 changes: 57 additions & 0 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 8a6513b

Please sign in to comment.