diff options
| author | nic-gaffney <gaffney_nic@protonmail.com> | 2023-06-26 22:51:03 -0500 |
|---|---|---|
| committer | nic-gaffney <gaffney_nic@protonmail.com> | 2023-06-26 22:51:03 -0500 |
| commit | e1733fc6b3875df434a4c3060bc70286e1f08014 (patch) | |
| tree | b7da493cea4771f35e9ca8c4b9584891d2194959 /std | |
| parent | 8c9bd55e161ba5fcaea626a1db2e0b685ac4f096 (diff) | |
| download | sloth-e1733fc6b3875df434a4c3060bc70286e1f08014.tar.gz | |
standard lib
Diffstat (limited to 'std')
| -rw-r--r-- | std/stdlib.c | 12 | ||||
| -rw-r--r-- | std/stdmath.c | 2 | ||||
| -rw-r--r-- | std/stdmath.sloth | 39 |
3 files changed, 27 insertions, 26 deletions
diff --git a/std/stdlib.c b/std/stdlib.c index 7e77385..11ae42f 100644 --- a/std/stdlib.c +++ b/std/stdlib.c @@ -2,18 +2,18 @@ #include <stdlib.h> #include <string.h> -void wait(long long x) { +void wait(int x) { sleep(x); } -long long slen(char *str) { - return (long long) strlen(str); +int slen(char *str) { + return (int) strlen(str); } -char charAt(char *str, long long x) { +char charAt(char *str, int x) { return str[x]; } -long long parse_int(char *str) { - return (long long) atoi(str); +int parse_int(char *str) { + return (int) atoi(str); } diff --git a/std/stdmath.c b/std/stdmath.c index dad292f..37c81b0 100644 --- a/std/stdmath.c +++ b/std/stdmath.c @@ -3,7 +3,7 @@ #include <time.h> -long long randGen(long long min, long long max) { +int randGen(int min, int max) { srandom((unsigned) time(NULL)); return random() % (max - min + 1) + min; } diff --git a/std/stdmath.sloth b/std/stdmath.sloth index 7ff5c82..9de73ae 100644 --- a/std/stdmath.sloth +++ b/std/stdmath.sloth @@ -42,28 +42,29 @@ fn fmin(x: Float, y: Float) Float { return y; } -fn pow(x: Int, y: Int) Int { - while y > 1 { - x = x*x; - y = y-1; +fn pow(x: Float, y: Float) Float { + var power: Float = x; + while y > 1.0 { + x = power*x; + y = y-1.0; } return x; } -fn floor(x: Float) Float { - return x - fabs(x % 1.0); -} +#fn floor(x: Float) Int { +# return x - fabs(x % 1); +#} -fn ceil(x: Float) Float { - if x < 0.0 { - return floor(x) - 1.0; - } - return floor(x) + 1.0; -} +#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) Float { +# if fabs(x % 1.0) >= 0.5 { +# return ceil(x); +# } +# return floor(x); +#} |
