1(* Author: Michael Norrish *)
2
3structure Arbintcore :> Arbintcore =
4struct
5
6open IntInf
7
8type num = Arbnumcore.num
9
10val zero = 0
11val one = 1
12val two = 2
13
14fun toString x =
15   (if x < 0
16       then "-" ^ (IntInf.toString (~x))
17    else IntInf.toString x) ^ "i"
18
19fun fromString s =
20   let
21      open Substring
22      val (pfx, rest) = splitl (fn c => c = #"-" orelse c = #"~") (full s)
23      val is_positive = Int.mod (size pfx, 2) = 0
24      val res = Arbnumcore.toLargeInt (Arbnumcore.fromString (string rest))
25   in
26      if is_positive then res else ~res
27   end
28
29val fromInt = IntInf.fromInt
30fun fromLargeInt x = x
31fun fromNat x = Arbnumcore.toLargeInt x
32val toInt = IntInf.toInt
33fun toLargeInt x = x
34fun toNat x =
35   if x < 0
36      then raise Fail "Attempt to make negative integer a nat"
37   else Arbnumcore.fromLargeInt x
38
39val divmod = divMod
40val quotrem = quotRem
41fun negate x = ~x
42
43end
44