36 |
fun op rem(a:int,b:int):int = I32.-(a, I32.*(b, I32.quot(a, b))) |
fun op rem(a:int,b:int):int = I32.-(a, I32.*(b, I32.quot(a, b))) |
37 |
fun abs(a:int):int = if I32.<(a, 0) then I32.~(a) else a |
fun abs(a:int):int = if I32.<(a, 0) then I32.~(a) else a |
38 |
|
|
39 |
fun op div(a:int, b:int):int = if I32.>=(b, 0) |
fun op div(a:int, b:int):int = |
40 |
then if I32.>=(a, 0) |
let val q = I32.quot (a, b) |
41 |
then I32.quot(a, b) |
in |
42 |
else I32.-(I32.quot(I32.+(a, 1), b), 1) |
if I32.>= (q, 0) then q |
43 |
else if I32.>(a,0) |
else if I32.= (a, I32.* (q, b)) then q |
44 |
then I32.-(I32.quot(I32.-(a, 1), b), 1) |
else I32.- (q, 1) |
45 |
else I32.quot(a, b) |
end |
46 |
|
|
47 |
fun op mod(a:int, b:int):int = if I32.>=(b, 0) |
fun op mod(a:int, b:int):int = |
48 |
then if I32.>=(a, 0) |
let val q = I32.quot (a, b) |
49 |
then I32.-(a, I32.*(I32.quot(a, b), b)) |
val r = I32.- (a, I32.* (q, b)) |
50 |
else I32.+(I32.-(a, I32.*(I32.quot(I32.+(a,1), b), b)), b) |
in |
51 |
else if I32.>(a, 0) |
if I32.>= (q, 0) orelse I32.= (r, 0) then r |
52 |
then I32.+(I32.-(a, I32.*(I32.quot(I32.-(a,1), b), b)), b) |
else I32.+ (r, b) |
53 |
else if I32.=(a, ~2147483648) andalso I32.=(b, ~1) |
end |
|
then 0 |
|
|
else I32.-(a, I32.*(I32.quot(a, b), b)) |
|
54 |
|
|
55 |
fun sign(0) = 0 |
fun sign(0) = 0 |
56 |
| sign i = if I32.<(i, 0) then ~1 else 1 |
| sign i = if I32.<(i, 0) then ~1 else 1 |