viper_binop_arith.py 493 Bytes
Newer Older
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
# test arithmetic operators

@micropython.viper
def add(x:int, y:int):
    print(x + y)
    print(y + x)
add(1, 2)
add(42, 3)
add(-1, 2)
add(-42, -3)

@micropython.viper
def sub(x:int, y:int):
    print(x - y)
    print(y - x)
sub(1, 2)
sub(42, 3)
sub(-1, 2)
sub(-42, -3)

@micropython.viper
def shl(x:int, y:int):
    print(x << y)
shl(1, 0)
shl(1, 3)
shl(1, 30)
shl(42, 10)
shl(-42, 10)

@micropython.viper
def shr(x:int, y:int):
    print(x >> y)
shr(1, 0)
shr(1, 3)
shr(42, 2)
shr(-42, 2)