From 52d6bc8533616dd642c96f8b6e72f459e1b4d465 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Mon, 17 Jul 2023 23:00:30 -0500 Subject: Standard lib rework --- std/stdmath.sloth | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'std/stdmath.sloth') diff --git a/std/stdmath.sloth b/std/stdmath.sloth index 9de73ae..28e3d38 100644 --- a/std/stdmath.sloth +++ b/std/stdmath.sloth @@ -1,5 +1,3 @@ -foreign fn randGen(min: Int, max: Int) Int; - fn abs(x: Int) Int { if x < 0 { return -x; @@ -51,20 +49,21 @@ fn pow(x: Float, y: Float) Float { return x; } -#fn floor(x: Float) Int { -# return x - fabs(x % 1); -#} +fn floor(x: Float) Int{ + return as_int(x - fabs(x % 1.0)); +} -#fn ceil(x: Float) Int { -# if x < 0.0 { -# return floor(x) - 1; -# } -# return floor(x) + 1; -#} +fn ceil(x: Float) Int { + if x < 0.0 { + return floor(x) - 1; + } + return floor(x) + 1; +} -#fn round(x: Float) Float { -# if fabs(x % 1.0) >= 0.5 { -# return ceil(x); -# } -# return floor(x); -#} +fn round(x: Float) Int { + var ret: Int = floor(x); + if fabs(x % 1.0) >= 0.5 { + ret = ceil(x); + } + return ret; +} -- cgit v1.2.3