From eee35a9bc41ced891c764cdfdc47f70c7146ffe3 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Mon, 31 Jan 2022 02:57:12 -0500 Subject: Add `std/math.cup` with some common math functions For now this is very limited, but shows the ability to import files! --- std/math.cup | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 std/math.cup diff --git a/std/math.cup b/std/math.cup new file mode 100644 index 0000000..9ac935c --- /dev/null +++ b/std/math.cup @@ -0,0 +1,22 @@ +fn min(a: int, b: int): int { + return a < b ? a : b; +} + +fn max(a: int, b: int): int { + return a > b ? a : b; +} + +fn sign(a: int): int { + return a > 0 ? 1 : a < 0 ? -1 : 0; +} + +fn abs(a: int): int { + return a * sign(a); +} + +fn factorial(n: int): int { + let res: int = 1; + for (;n > 0; n = n - 1) + res = res * n; + return res; +} \ No newline at end of file -- cgit v1.2.3