diff options
| author | Cody <cody@codyq.dev> | 2023-07-20 18:13:34 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-07-20 18:13:34 -0500 |
| commit | 1219f5ed8aed0bcb6a416a194fce70f0a290309d (patch) | |
| tree | 5759c263bc626d288cb69434d1f46e20af49f2de /std/stdmath.sloth | |
| parent | 7c53e65cad365ec112d2ec1bd9c3091dbed05720 (diff) | |
| parent | 52d6bc8533616dd642c96f8b6e72f459e1b4d465 (diff) | |
| download | sloth-1219f5ed8aed0bcb6a416a194fce70f0a290309d.tar.gz | |
Merge branch 'master' of github.com:slothlang/slothlang
Diffstat (limited to 'std/stdmath.sloth')
| -rw-r--r-- | std/stdmath.sloth | 33 |
1 files changed, 16 insertions, 17 deletions
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; +} |
