Skip to content

Commit

Permalink
float stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-gaffney committed Aug 20, 2023
1 parent 1e1aeb4 commit 5cf0b81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions std/extern.sloth
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ foreign fn slen(str: String) Int;
foreign fn parse_int(str: String) Int;
foreign fn termpos(x: Int, y: Int);
foreign fn as_int(x: Float) Int;
foreign fn as_float(x: Int) Float;
foreign fn istr(x: Int) String;
foreign fn fstr(x: Float) String;
foreign fn system(cmd: String) Int;
foreign fn sequals(a: String, b: String) Bool;
foreign fn termclear() Void;
Expand Down
11 changes: 11 additions & 0 deletions std/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ int as_int(float x) {
return (int) x;
}

int as_float(int x) {
return (float) x;
}

bool sequals(char* a, char* b) {
if (strlen(a) != strlen(b)) {
return false;
Expand All @@ -59,3 +63,10 @@ char* istr(int x) {
//char* result = snum;
return snum;
}

char* fstr(float x) {
char* snum = malloc(12);
sprintf(snum, "%f", x);
//char* result = snum;
return snum;
}

0 comments on commit 5cf0b81

Please sign in to comment.