File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,12 @@ pub method mod {~__line__, ~__file__} (self : Int) (n : Int) =
2929 assert {msg="Division by zero"} (n != 0);
3030 (extern dbl_modInt : Int -> Int -> Int) self n
3131
32+ pub method rec pow {~__line__, ~__file__} (self : Int) (n : Int) =
33+ assert {msg="Negative exponential"} (n >= 0);
34+ if n == 0 then 1
35+ else if n % 2 == 0 then (self * self).pow (n / 2)
36+ else self * (self * self).pow (n / 2)
37+
3238pub method neg (self : Int) = 0 - self
3339
3440pub method land = (extern dbl_andInt : Int -> Int -> Int)
Original file line number Diff line number Diff line change @@ -18,13 +18,20 @@ pub method neg = (extern dbl_negInt64 : Int64 -> Int64)
1818pub method add = (extern dbl_addInt64 : Int64 -> Int64 -> Int64)
1919pub method sub = (extern dbl_subInt64 : Int64 -> Int64 -> Int64)
2020pub method mul = (extern dbl_mulInt64 : Int64 -> Int64 -> Int64)
21+
2122pub method div {~__line__, ~__file__} (self : Int64) (n : Int64) =
22- assert {msg="Division by zero"} (n.neq 0L);
23+ assert {msg="Division by zero"} (n != 0L);
2324 (extern dbl_divInt64 : Int64 -> Int64 -> Int64) self n
2425pub method mod {~__line__, ~__file__} (self : Int64) (n : Int64) =
25- assert {msg="Division by zero"} (n.neq 0L);
26+ assert {msg="Division by zero"} (n != 0L);
2627 (extern dbl_modInt64 : Int64 -> Int64 -> Int64) self n
2728
29+ pub method rec pow {~__line__, ~__file__} (self : Int64) (n : Int64) =
30+ assert {msg="Negative exponential"} (n >= 0L);
31+ if n == 0L then 1L
32+ else if n % 2L == 0L then (self * self).pow (n / 2L)
33+ else self * (self * self).pow (n / 2L)
34+
2835pub method land = (extern dbl_andInt64 : Int64 -> Int64 -> Int64)
2936pub method lor = (extern dbl_orInt64 : Int64 -> Int64 -> Int64)
3037pub method lxor = (extern dbl_xorInt64 : Int64 -> Int64 -> Int64)
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ pub let (/)
1919 , method div : {~__line__, ~__file__} -> T -> U} (x : T) =
2020 x.div
2121pub let (*) {method mul : T -> U} (x : T) = x.mul
22+ pub let (**)
23+ { ~__line__, ~__file__
24+ , method pow : {~__line__, ~__file__} -> T -> U} (x : T) =
25+ x.pow
2226
2327pub let (==) {method equal : T -> U} (x : T) = x.equal
2428pub let (!=) {method neq : T -> U} (x : T) = x.neq
You can’t perform that action at this time.
0 commit comments