From 5cf0b81fd353041401b697c8a50694218b6b09b2 Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Sat, 19 Aug 2023 20:53:48 -0500 Subject: [PATCH] float stuff --- std/extern.sloth | 2 ++ std/stdlib.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/std/extern.sloth b/std/extern.sloth index c970541..6405c8a 100644 --- a/std/extern.sloth +++ b/std/extern.sloth @@ -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; diff --git a/std/stdlib.c b/std/stdlib.c index ed848c3..6fa966d 100644 --- a/std/stdlib.c +++ b/std/stdlib.c @@ -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; @@ -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; +}