circuitpython/tests/micropython/viper_binop_arith.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
992 B
Python
Raw Permalink Normal View History

# test arithmetic operators
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def add(x: int, y: int):
print(x + y)
print(y + x)
2021-03-15 09:57:36 -04:00
add(1, 2)
add(42, 3)
add(-1, 2)
add(-42, -3)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def sub(x: int, y: int):
print(x - y)
print(y - x)
2021-03-15 09:57:36 -04:00
sub(1, 2)
sub(42, 3)
sub(-1, 2)
sub(-42, -3)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def mul(x: int, y: int):
print(x * y)
print(y * x)
2021-03-15 09:57:36 -04:00
mul(0, 1)
mul(1, -1)
mul(1, 2)
mul(8, 3)
mul(-3, 4)
mul(-9, -6)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def shl(x: int, y: int):
print(x << y)
2021-03-15 09:57:36 -04:00
shl(1, 0)
shl(1, 3)
shl(1, 30)
shl(42, 10)
shl(-42, 10)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def shr(x: int, y: int):
print(x >> y)
2021-03-15 09:57:36 -04:00
shr(1, 0)
shr(1, 3)
shr(42, 2)
shr(-42, 2)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def and_(x: int, y: int):
print(x & y, y & x)
2021-03-15 09:57:36 -04:00
and_(1, 0)
and_(1, 3)
2021-03-15 09:57:36 -04:00
and_(0xF0, 0x3F)
and_(-42, 6)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def or_(x: int, y: int):
print(x | y, y | x)
2021-03-15 09:57:36 -04:00
or_(1, 0)
or_(1, 2)
or_(-42, 5)
2021-03-15 09:57:36 -04:00
@micropython.viper
2021-03-15 09:57:36 -04:00
def xor(x: int, y: int):
print(x ^ y, y ^ x)
2021-03-15 09:57:36 -04:00
xor(1, 0)
xor(1, 2)
xor(-42, 5)