1 For integers, the ucode VM tries to perform unsigned 64bit arithmetic internally 2 if both operands are positive or if the result is guaranteed to be positive. 3 4 In all other cases, calculations are performed using signed 64bit arithmetic 5 with wrap arounds using twos-complement representation. 6 7 Due to this, the minimum and maximum representable values depend on the values 8 of the involved operands. 9 10 -- Testcase -- 11 Unsigned additions roll over back to zero: 12 {{ 18446744073709551615 + 1 }} 13 14 Unsigned multiplications roll over back to zero: 15 {{ 9223372036854775808 * 2 }} 16 17 Signed additions roll over at INT64_MIN/INT64_MAX: 18 {{ -9223372036854775808 + -1 }} 19 20 Signed multiplications roll over back to INT64_MIN: 21 {{ 18446744073709551615 * -1 }} 22 23 Multiplicating two negative operands yields an unsigned result. 24 {{ -9223372036854775807 * -2 }} 25 26 Signed calculations yielding positive results are promoted to unsigned. 27 {{ -9223372036854775808 + 9223372036854775808 + -9223372036854775807 * -2 }} 28 29 Substractions roll over to INT64_MAX on underflow: 30 {{ 0 - 9223372036854775809 }} 31 -- End -- 32 33 -- Expect stdout -- 34 Unsigned additions roll over back to zero: 35 0 36 37 Unsigned multiplications roll over back to zero: 38 0 39 40 Signed additions roll over at INT64_MIN/INT64_MAX: 41 9223372036854775807 42 43 Signed multiplications roll over back to INT64_MIN: 44 -9223372036854775807 45 46 Multiplicating two negative operands yields an unsigned result. 47 18446744073709551614 48 49 Signed calculations yielding positive results are promoted to unsigned. 50 18446744073709551614 51 52 Substractions roll over to INT64_MAX on underflow: 53 9223372036854775807 54 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt