summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/01_arithmetic/03_bitwise
blob: c481b3e1ffd82cda353a01a98ebccf56c64c5b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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:
10 << 2 = 40
3.3 << 4.1 = 48

Right shift:
10 >> 2 = 2
3.3 >> 4.1 = 0

Bitwise and:
1234 & 200 = 192
120.3 & 54.3 = 48

Bitwise xor:
1234 ^ 200 = 1050
120.3 ^ 54.3 = 78

Bitwise or:
1234 | 200 = 1242
120.3 | 54.3 = 126

Complement:
~0 = 18446744073709551615
~10.4 = 18446744073709551605
-- End --

-- Testcase --
Left shift:
10 << 2 = {{ 10 << 2 }}
3.3 << 4.1 = {{ 3.3 << 4.1 }}

Right shift:
10 >> 2 = {{ 10 >> 2 }}
3.3 >> 4.1 = {{ 3.3 >> 4.1 }}

Bitwise and:
1234 & 200 = {{ 1234 & 200 }}
120.3 & 54.3 = {{ 120.3 & 54.3 }}

Bitwise xor:
1234 ^ 200 = {{ 1234 ^ 200 }}
120.3 ^ 54.3 = {{ 120.3 ^ 54.3 }}

Bitwise or:
1234 | 200 = {{ 1234 | 200 }}
120.3 | 54.3 = {{ 120.3 | 54.3 }}

Complement:
~0 = {{ ~0 }}
~10.4 = {{ ~10.4 }}
-- End --