diff options
author | Tom Smeding <tom@tomsmeding.com> | 2021-09-19 18:06:03 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2021-09-19 18:06:03 +0200 |
commit | 956a60dc5253da43dc0fddaecf88116597023fdf (patch) | |
tree | f56402103483c853a0bdd7551092418025156e51 /prelude.c |
Initial
Diffstat (limited to 'prelude.c')
-rw-r--r-- | prelude.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/prelude.c b/prelude.c new file mode 100644 index 0000000..bb345c4 --- /dev/null +++ b/prelude.c @@ -0,0 +1,13 @@ +int builtin_divInt(int x, int y) { + return + (x > 0 && y < 0) ? (x - 1) / y - 1 + : (x < 0 && y > 0) ? (x + 1) / y - 1 + : x / y; +} + +int builtin_modInt(int x, int y) { + return + (x > 0 && y < 0) ? (x - 1) % y + y + 1 + : (x < 0 && y > 0) ? (x + 1) % y + y - 1 + : x % y; +} |