check.bend
bend-osdev-u32@0.1.0.0 · 36 lines · 4 definitions
1import Base
2import bend-osdev-u32@0.1.0.0/u32.bend as U
3
4
5def add_lhs(+a: U32, +b: U32) -> Nat:
6 Nat.add(U32.to_nat(U32.add(a, b)), U.U32Nat.dbl(32n, U.U32Nat.bit(U32.is_lt(U32.add(a, b), a))))
7
8def sub_lhs(+a: U32, +b: U32) -> Nat:
9 Nat.add(U32.to_nat(U32.sub(a, b)), U32.to_nat(b))
10
11def sub_rhs(+a: U32, +b: U32) -> Nat:
12 Nat.add(U32.to_nat(a), U.U32Nat.dbl(32n, U.U32Nat.bit(U32.is_lt(a, b))))
13
14def main() -> IO(Unit):
15 do IO<Unit>:
16 IO.print(Nat.show(U.U32Nat.dbl(32n, 1n)))
17 IO.print(Nat.show(U.U32Nat.dbl(3n, 5n)))
18 IO.print(Nat.show(U.U32Nat.half(1001n)))
19 IO.print(Nat.show(add_lhs(4294967295, 2)))
20 IO.print(Nat.show(Nat.add(U32.to_nat(4294967295), U32.to_nat(2))))
21 IO.print(Nat.show(add_lhs(3000000000, 1000000000)))
22 IO.print(Nat.show(sub_lhs(1, 3)))
23 IO.print(Nat.show(sub_rhs(1, 3)))
24 IO.print(Nat.show(sub_lhs(7, 3)))
25 IO.print(Nat.show(U32.to_nat(U32.shln(3, 30n))))
26
27
28
29
30
31
32
33
34
35
36