summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/01_arithmetic/05_overflow
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-04 16:16:28 +0100
committerGitHub <noreply@github.com>2022-01-04 16:16:28 +0100
commit1377e23afff90128b18ac60c10071295fc0afbab (patch)
tree04397dab9be96a5978e08366299671a8aa507267 /tests/custom/01_arithmetic/05_overflow
parent8907ce41a36f8d42097d884550fb3cfbba62e6c5 (diff)
parentb605dbfcf04f310e08634b52507da7a4155bfce1 (diff)
Merge pull request #30 from jow-/rework-number-handling
treewide: rework numeric value handling
Diffstat (limited to 'tests/custom/01_arithmetic/05_overflow')
-rw-r--r--tests/custom/01_arithmetic/05_overflow54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/custom/01_arithmetic/05_overflow b/tests/custom/01_arithmetic/05_overflow
new file mode 100644
index 0000000..8c2f214
--- /dev/null
+++ b/tests/custom/01_arithmetic/05_overflow
@@ -0,0 +1,54 @@
+For integers, the ucode VM tries to perform unsigned 64bit arithmetic internally
+if both operands are positive or if the result is guaranteed to be positive.
+
+In all other cases, calculations are performed using signed 64bit arithmetic
+with wrap arounds using twos-complement representation.
+
+Due to this, the minimum and maximum representable values depend on the values
+of the involved operands.
+
+-- Testcase --
+Unsigned additions roll over back to zero:
+{{ 18446744073709551615 + 1 }}
+
+Unsigned multiplications roll over back to zero:
+{{ 9223372036854775808 * 2 }}
+
+Signed additions roll over at INT64_MIN/INT64_MAX:
+{{ -9223372036854775808 + -1 }}
+
+Signed multiplications roll over back to INT64_MIN:
+{{ 18446744073709551615 * -1 }}
+
+Multiplicating two negative operands yields an unsigned result.
+{{ -9223372036854775807 * -2 }}
+
+Signed calculations yielding positive results are promoted to unsigned.
+{{ -9223372036854775808 + 9223372036854775808 + -9223372036854775807 * -2 }}
+
+Substractions roll over to INT64_MAX on underflow:
+{{ 0 - 9223372036854775809 }}
+-- End --
+
+-- Expect stdout --
+Unsigned additions roll over back to zero:
+0
+
+Unsigned multiplications roll over back to zero:
+0
+
+Signed additions roll over at INT64_MIN/INT64_MAX:
+9223372036854775807
+
+Signed multiplications roll over back to INT64_MIN:
+-9223372036854775807
+
+Multiplicating two negative operands yields an unsigned result.
+18446744073709551614
+
+Signed calculations yielding positive results are promoted to unsigned.
+18446744073709551614
+
+Substractions roll over to INT64_MAX on underflow:
+9223372036854775807
+-- End --