-
Notifications
You must be signed in to change notification settings - Fork 0
/
i8.ya
121 lines (91 loc) · 3.35 KB
/
i8.ya
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package i8
import bool
import is
import pair
import maybe
import u32
where
def I8: Type = #I8
def I8.MAX: I8 = #I8.max
def I8.MIN: I8 = #I8.min
def I8.abs: ∀ (x: I8) -> #U8 = #I8.abs
def I8.sgn: ∀ (x: I8) -> Bool = #I8.sgn
def I8.eql: ∀ (x y: I8) -> Bool = #I8.eql
def I8.lte: ∀ (x y: I8) -> Bool = #I8.lte
def I8.lth: ∀ (x y: I8) -> Bool = #I8.lth
def I8.gte: ∀ (x y: I8) -> Bool = #I8.gte
def I8.gth: ∀ (x y: I8) -> Bool = #I8.gth
def I8.and: ∀ (x y: I8) -> Bool = #I8.and
def I8.xor: ∀ (x y: I8) -> Bool = #I8.xor
def I8.or: ∀ (x y: I8) -> Bool = #I8.or
def I8.neq (x y: I8): Bool = Bool.not (I8.eql x y)
def I8.add: ∀ (x y: I8) -> I8 = #I8.add
def I8.SafeAdd (x y: I8): Bool =
Bool.not
(Bool.and
(Bool.eql (I8.sgn x) (I8.sgn y))
(Bool.neq (I8.sgn x) (I8.sgn (#I8.add x y)))
)
def I8.addSafe (x y: I8) (0 e: Is (I8.SafeAdd x y)): I8 = #I8.add x y
def I8.sub: ∀ (x y: I8) -> I8 = #I8.sub
def I8.SafeSub (x y: I8): Bool =
Bool.not
(Bool.and
(Bool.eql (I8.sgn x) (Bool.not (I8.sgn y)))
(Bool.neq (I8.sgn x) (I8.sgn (#I8.sub x y)))
)
def I8.subSafe (x y: I8) (0 e: Is (I8.lte y x)): I8 = #I8.sub x y
def I8.mul: ∀ (x y: I8) -> I8 = #I8.mul
def I8.SafeMul (x y: I8): Bool =
Bool.or (I8.eql x +0i8)
((case (I8.eql y +0i8)) (λ _ => Bool)
Bool.True
(I8.eql (#I8.div (#I8.mul x y) y) x)
)
def I8.mulSafe (x y: I8) (0 e: Is (I8.SafeMul x y)): I8 = #I8.mul x y
def I8.div (x y: I8): Maybe I8 =
(case (I8.neq y +0i8)) (λ _ => Maybe I8)
(Maybe.Some I8 (#I8.div x y))
(Maybe.None I8)
def I8.divSafe (x y: I8) (0 e: Is (I8.neq y +0i8)): I8 = #I8.div x y
def I8.mod (x y: I8): Maybe I8 =
(case (I8.neq y +0i8)) (λ _ => Maybe I8)
(Maybe.Some I8 (#I8.mod x y))
(Maybe.None I8)
def I8.modSafe (x y: I8) (0 e: Is (I8.neq y +0i8)): I8 = #I8.mod x y
def I8.pow: ∀ (x: I8) (y: U32) -> I8 = #I8.pow
def I8.shl: ∀ (x: U32) (y: I8) -> I8 = #I8.shl
def I8.shr: ∀ (x: U32) (y: I8) -> I8 = #I8.shr
def I8.rol: ∀ (x: U32) (y: I8) -> I8 = #I8.rol
def I8.ror: ∀ (x: U32) (y: I8) -> I8 = #I8.ror
def I8.countZeros: ∀ (x: I8) -> U32 = #I8.count_zeros
def I8.countOnes: ∀ (x: I8) -> U32 = #I8.count_ones
def I8.toU8 (x: I8): Maybe #U8 =
(case (I8.sgn x)) (λ _ => Maybe #U8)
(Maybe.Some #U8 (#I8.to_U8 x))
(Maybe.None #U8)
def I8.toU8Safe (x: I8) (0 e: Is (I8.sgn x)): #U8 = #I8.to_U8 x
def I8.toU16 (x: I8): Maybe #U16 =
(case (I8.sgn x)) (λ _ => Maybe #U16)
(Maybe.Some #U16 (#I8.to_U16 x))
(Maybe.None #U16)
def I8.toU16Safe (x: I8) (0 e: Is (I8.sgn x)): #U16 = #I8.to_U16 x
def I8.toU32 (x: I8): Maybe #U32 =
(case (I8.sgn x)) (λ _ => Maybe #U32)
(Maybe.Some #U32 (#I8.to_U32 x))
(Maybe.None #U32)
def I8.toU32Safe (x: I8) (0 e: Is (I8.sgn x)): #U32 = #I8.to_U32 x
def I8.toU64 (x: I8): Maybe #U64 =
(case (I8.sgn x)) (λ _ => Maybe #U64)
(Maybe.Some #U64 (#I8.to_U64 x))
(Maybe.None #U64)
def I8.toU64Safe (x: I8) (0 e: Is (I8.sgn x)): #U64 = #I8.to_U64 x
def I8.toNat (x: I8): Maybe #Nat =
(case (I8.sgn x)) (λ _ => Maybe #Nat)
(Maybe.Some #Nat (#I8.to_Nat x))
(Maybe.None #Nat)
def I8.toNatSafe (x: I8) (0 e: Is (I8.sgn x)): #Nat = #I8.to_Nat x
def I8.toI16: ∀ (x: I8) -> #I16 = #I8.to_I16
def I8.toI32: ∀ (x: I8) -> #I32 = #I8.to_I32
def I8.toI64: ∀ (x: I8) -> #I64 = #I8.to_I64
def I8.toInt: ∀ (x: I8) -> #Int = #I8.to_Int