circuitpython/tests/micropython/viper_binop_arith_uint.py
Damien George 41fa8b5482 py/emitnative: Implement binary operations for viper uint operands.
uint types in viper mode can now be used for all binary operators except
floor-divide and modulo.

Fixes issue #1847 and issue #6177.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-27 00:24:04 +10:00

33 lines
541 B
Python

# test arithmetic operators with uint type
@micropython.viper
def add(x: uint, y: uint):
return x + y, y + x
print("add")
print(*add(1, 2))
print(*(x & 0xFFFFFFFF for x in add(-1, -2)))
@micropython.viper
def sub(x: uint, y: uint):
return x - y, y - x
print("sub")
print(*(x & 0xFFFFFFFF for x in sub(1, 2)))
print(*(x & 0xFFFFFFFF for x in sub(-1, -2)))
@micropython.viper
def mul(x: uint, y: uint):
return x * y, y * x
print("mul")
print(*mul(2, 3))
print(*(x & 0xFFFFFFFF for x in mul(2, -3)))
print(*mul(-2, -3))