diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2023-07-17 23:00:30 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2023-07-17 23:00:30 -0500 |
| commit | 52d6bc8533616dd642c96f8b6e72f459e1b4d465 (patch) | |
| tree | 31f3dc1f3378151e57f7bc37fa2b4e22ab757661 /std/stdmath.sloth | |
| parent | ee2133a13d61b3b3fb8fcf88f9c9781debd77d9e (diff) | |
| download | sloth-52d6bc8533616dd642c96f8b6e72f459e1b4d465.tar.gz | |
Standard lib rework
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; +} |
