aboutsummaryrefslogtreecommitdiff
path: root/std/math.cup
diff options
context:
space:
mode:
Diffstat (limited to 'std/math.cup')
-rw-r--r--std/math.cup22
1 files changed, 22 insertions, 0 deletions
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