diff options
Diffstat (limited to 'tests/custom/01_arithmetic')
-rw-r--r-- | tests/custom/01_arithmetic/02_modulo | 23 | ||||
-rw-r--r-- | tests/custom/01_arithmetic/03_bitwise | 10 | ||||
-rw-r--r-- | tests/custom/01_arithmetic/05_overflow | 54 |
3 files changed, 71 insertions, 16 deletions
diff --git a/tests/custom/01_arithmetic/02_modulo b/tests/custom/01_arithmetic/02_modulo index 244d624..c011e04 100644 --- a/tests/custom/01_arithmetic/02_modulo +++ b/tests/custom/01_arithmetic/02_modulo @@ -1,32 +1,31 @@ -The utpl language supports modulo divisions, however they're only defined -for integer values. +The ucode language supports modulo divisions. -- Expect stdout -- If both operands are integers or convertible to integers, -the modulo division yields the remainder: +the modulo division yields the remaining integer value: 10 % 4 = 2 "10" % 4 = 2 10 % "4" = 2 "10" % "4" = 2 If either operand is a double value, the modulo operation -yields NaN: -10.0 % 4 = NaN -10 % 4.0 = NaN -"10.0" % 4 = NaN +yields the remaining value as calculated by fmod(3): +10.2 % 4 = 2.2 +10 % 4.3 = 1.4 +"10.4" % 4 = 2.4 -- End -- -- Testcase -- If both operands are integers or convertible to integers, -the modulo division yields the remainder: +the modulo division yields the remaining integer value: 10 % 4 = {{ 10 % 4 }} "10" % 4 = {{ "10" % 4 }} 10 % "4" = {{ 10 % 4 }} "10" % "4" = {{ "10" % "4" }} If either operand is a double value, the modulo operation -yields NaN: -10.0 % 4 = {{ 10.0 % 4 }} -10 % 4.0 = {{ 10 % 4.0 }} -"10.0" % 4 = {{ "10.0" % 4 }} +yields the remaining value as calculated by fmod(3): +10.2 % 4 = {{ 10.2 % 4 }} +10 % 4.3 = {{ 10 % 4.3 }} +"10.4" % 4 = {{ "10.4" % 4 }} -- End -- diff --git a/tests/custom/01_arithmetic/03_bitwise b/tests/custom/01_arithmetic/03_bitwise index faf4ffd..c481b3e 100644 --- a/tests/custom/01_arithmetic/03_bitwise +++ b/tests/custom/01_arithmetic/03_bitwise @@ -1,5 +1,7 @@ -Utpl implements C-style bitwise operations. One detail is that these operations -coerce their operands to signed 64bit integer values internally. +Ucode implements C-style bitwise operations. One detail is that these operations +coerce their operands to 64bit integer values internally. If both operands are +positive, unsigned 64bit semantics are used. If one of the operands is negative, +both are converted to signed 64bit numbers. -- Expect stdout -- Left shift: @@ -23,8 +25,8 @@ Bitwise or: 120.3 | 54.3 = 126 Complement: -~0 = -1 -~10.4 = -11 +~0 = 18446744073709551615 +~10.4 = 18446744073709551605 -- End -- -- Testcase -- 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 -- |