aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-01-31 02:57:12 -0500
committerMustafa Quraish <[email protected]>2022-01-31 02:57:12 -0500
commiteee35a9bc41ced891c764cdfdc47f70c7146ffe3 (patch)
tree14ee6bf10dc0f5fbae1f9183d8f9bcef1ca23fdc /std
parentAdd ability to import other files (diff)
downloadcup-eee35a9bc41ced891c764cdfdc47f70c7146ffe3.tar.xz
cup-eee35a9bc41ced891c764cdfdc47f70c7146ffe3.zip
Add `std/math.cup` with some common math functions
For now this is very limited, but shows the ability to import files!
Diffstat (limited to 'std')
-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