src/Pure/General/integer.ML
changeset 67033 2288cc39b038
parent 66997 17eb23e43630
child 67074 5da20135f560
equal deleted inserted replaced
67031:22a47374a205 67033:2288cc39b038
    38 
    38 
    39 fun div_mod x y = IntInf.divMod (x, y);
    39 fun div_mod x y = IntInf.divMod (x, y);
    40 
    40 
    41 fun square x = x * x;
    41 fun square x = x * x;
    42 
    42 
    43 fun pow k l =
    43 fun pow k l = IntInf.pow (l, k);
    44   let
       
    45     fun pw 0 _ = 1
       
    46       | pw 1 l = l
       
    47       | pw k l =
       
    48           let
       
    49             val (k', r) = div_mod k 2;
       
    50             val l' = pw k' (l * l);
       
    51           in if r = 0 then l' else l' * l end;
       
    52   in
       
    53     if k < 0
       
    54     then IntInf.pow (l, k)
       
    55     else pw k l
       
    56   end;
       
    57 
    44 
    58 fun gcd x y = PolyML.IntInf.gcd (x, y);
    45 fun gcd x y = PolyML.IntInf.gcd (x, y);
    59 fun lcm x y = abs (PolyML.IntInf.lcm (x, y));
    46 fun lcm x y = abs (PolyML.IntInf.lcm (x, y));
    60 
    47 
    61 fun gcds [] = 0
    48 fun gcds [] = 0
    63 
    50 
    64 fun lcms [] = 1
    51 fun lcms [] = 1
    65   | lcms (x :: xs) = abs (Library.foldl PolyML.IntInf.lcm (x, xs));
    52   | lcms (x :: xs) = abs (Library.foldl PolyML.IntInf.lcm (x, xs));
    66 
    53 
    67 end;
    54 end;
    68 
       
    69 (* FIXME workaround for Poly/ML 5.7.1 testing *)
       
    70 structure IntInf =
       
    71 struct
       
    72   open IntInf;
       
    73   fun pow (i, n) = Integer.pow n i;
       
    74 end