summaryrefslogtreecommitdiff
path: root/tests/typ/compute
diff options
context:
space:
mode:
authorPgBiel <9021226+PgBiel@users.noreply.github.com>2024-01-25 12:07:11 -0300
committerGitHub <noreply@github.com>2024-01-25 15:07:11 +0000
commit47b8d61cd88664cc3ab74196b5464f9f5b1bfbf3 (patch)
tree1d1e17322b7b58457003406e5a1d2a5e7e9c0d55 /tests/typ/compute
parent2a8e40f282d30398a256748b9b6412ab2a6dd279 (diff)
Implement bitwise operations on integers (#3130)
Diffstat (limited to 'tests/typ/compute')
-rw-r--r--tests/typ/compute/calc.typ43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ
index 68f76b39..db03af49 100644
--- a/tests/typ/compute/calc.typ
+++ b/tests/typ/compute/calc.typ
@@ -168,6 +168,49 @@
#test(calc.ln(10), calc.log(10, base: calc.e))
---
+// Test the `bit-not`, `bit-and`, `bit-or` and `bit-xor` functions.
+#test(64.bit-not(), -65)
+#test(0.bit-not(), -1)
+#test((-56).bit-not(), 55)
+#test(128.bit-and(192), 128)
+#test(192.bit-and(224), 192)
+#test((-1).bit-and(325532), 325532)
+#test(0.bit-and(-53), 0)
+#test(0.bit-or(-1), -1)
+#test(5.bit-or(3), 7)
+#test((-50).bit-or(3), -49)
+#test(64.bit-or(32), 96)
+#test((-1).bit-xor(1), -2)
+#test(64.bit-xor(96), 32)
+#test((-1).bit-xor(-7), 6)
+#test(0.bit-xor(492), 492)
+
+---
+// Test the `bit-lshift` and `bit-rshift` functions.
+#test(32.bit-lshift(2), 128)
+#test(694.bit-lshift(0), 694)
+#test(128.bit-rshift(2), 32)
+#test(128.bit-rshift(12345), 0)
+#test((-7).bit-rshift(2), -2)
+#test((-7).bit-rshift(12345), -1)
+#test(128.bit-rshift(2, logical: true), 32)
+#test((-7).bit-rshift(61, logical: true), 7)
+#test(128.bit-rshift(12345, logical: true), 0)
+#test((-7).bit-rshift(12345, logical: true), 0)
+
+---
+// Error: 2-18 the result is too large
+#1.bit-lshift(64)
+
+---
+// Error: 15-17 number must be at least zero
+#1.bit-lshift(-1)
+
+---
+// Error: 15-17 number must be at least zero
+#1.bit-rshift(-1)
+
+---
// Error: 10-16 zero to the power of zero is undefined
#calc.pow(0, 0)