check.bend

bend-osdev-word64@0.1.1.0 · 46 lines · 3 definitions

1import Base
2import bend-osdev-word64@0.1.1.0/word64.bend as W
3
4# 10^12 = 0xE8_D4A51000
5def trillion() -> W.W64:
6  W.W64.from_parts(232, 3567587328)
7
8# a / b and a mod b, as decimal text
9def dm(+a: W.W64, +b: W.W64) -> String:
10  W.W64.show(W.W64.div(a, b)) ++ " " ++ W.W64.show(W.W64.mod(a, b))
11
12def main() -> IO(Unit):
13  do IO<Unit>:
14    IO.print(W.W64.show(W.W64.max()))
15    IO.print(W.W64.show_hex(W.W64.add(W.W64.max(), W.W64.one())))
16    IO.print(W.W64.show_hex(W.W64.mul(W.W64.from_u32(4294967295), W.W64.from_u32(4294967295))))
17    IO.print(W.W64.show_hex(W.W64.shl(W.W64.from_parts(3735928559, 3405691582), 8n)))
18    IO.print(U32.show(W.W64.hi(W.W64.from_parts(7, 9))))
19    IO.print(W.W64.show(W.W64.div(trillion(), W.W64.from_u32(7))))
20    IO.print(W.W64.show(W.W64.mod(trillion(), W.W64.from_u32(7))))
21    IO.print(Bool.show(W.W64.is_lt(W.W64.from_parts(1, 0), W.W64.from_parts(0, 4294967295))))
22    IO.print(dm(W.W64.from_parts(3735928559, 3405691582), W.W64.from_parts(0, 0)))
23    IO.print(dm(W.W64.from_parts(4294967295, 4294967295), W.W64.from_parts(0, 1)))
24    IO.print(dm(W.W64.from_parts(0, 5), W.W64.from_parts(0, 7)))
25    IO.print(dm(W.W64.from_parts(2147483648, 5), W.W64.from_parts(2147483648, 5)))
26    IO.print(dm(W.W64.from_parts(4294967295, 4294967295), W.W64.from_parts(2147483648, 1)))
27    IO.print(dm(W.W64.from_parts(2147483648, 3), W.W64.from_parts(0, 3)))
28    IO.print(dm(W.W64.from_parts(4294967295, 4294967295), W.W64.from_parts(1, 1)))
29    IO.print(dm(W.W64.from_parts(305419896, 2596069104), W.W64.from_parts(0, 267242409)))
30
31#|18446744073709551615
32#|0000000000000000
33#|fffffffe00000001
34#|adbeefcafebabe00
35#|7
36#|142857142857
37#|1
38#|False
39#|0 16045690984503098046
40#|18446744073709551615 0
41#|0 5
42#|1 0
43#|1 9223372036854775806
44#|3074457345618258603 2
45#|4294967295 0
46#|4908534062 76354962