1(* Copyright (c) Michael Norrish *)
2
3structure mlibOmegaint :> mlibOmegaint =
4struct
5  structure I = IntInf; local open IntInf in end;
6  structure V = Vector; local open Vector in end;
7  structure W = Word; local open Word in end;
8
9  val zero = I.fromInt 0;
10  val one = I.fromInt 1;
11  val eq = op=;
12  val == = eq
13  infix ==
14
15  (*
16  fun hash n =
17    case M.rep n of
18      M.Small w => w
19    | M.Big v   =>
20        let val k = W.toIntX (V.foldli (fn (_,w,acc) => w + acc) 0w0 (v,1,NONE))
21        in if V.sub (v,0) = 0w0 then k else ~k
22        end;
23        *)
24
25
26   (*------------------------------------------------------------------------*)
27   (* Function to compute the Greatest Common Divisor of two integers.       *)
28   (*------------------------------------------------------------------------*)
29
30   (*
31  fun hash n =
32    case M.rep n of
33      M.Small w => w
34    | M.Big v   =>
35        let val k = W.toIntX (V.foldli (fn (_,w,acc) => w + acc) 0w0 (v,1,NONE))
36        in if V.sub (v,0) = 0w0 then k else ~k
37        end;
38        *)
39   fun hash n = IntInf.toInt n
40
41
42   open I
43   fun ERR f s = raise Fail ("Function: "^f^", message: "^s)
44
45   fun gcd' i j = let
46       val r = i mod j
47   in  if r == zero then j else gcd' j r
48   end
49
50   fun gcd (i,j) =
51       if i < zero orelse j < zero then ERR "gcd""negative arguments to gcd"
52       else if i == zero then j else if j == zero then i
53                                else if i < j then gcd' j i else gcd' i j
54
55end
56