| 1 | structure II = IntInf |
| 2 | structure MII = MLton.IntInf |
| 3 | |
| 4 | structure BigWord = MLton.IntInf.BigWord |
| 5 | structure SmallInt = MLton.IntInf.SmallInt |
| 6 | datatype rep = datatype MLton.IntInf.rep |
| 7 | val toRep = MLton.IntInf.rep |
| 8 | val fromRep = MLton.IntInf.fromRep |
| 9 | |
| 10 | fun checkToFrom ii = |
| 11 | let |
| 12 | fun bug str = |
| 13 | print (concat ["checkToFrom ", |
| 14 | IntInf.toString ii, |
| 15 | " => ", |
| 16 | str, |
| 17 | "\n"]) |
| 18 | val r = toRep ii |
| 19 | val () = |
| 20 | if false |
| 21 | then print (concat ["toRep ", IntInf.toString ii, " = ", |
| 22 | case r of |
| 23 | Big _ => "Big\n" |
| 24 | | Small _ => "Small\n"]) |
| 25 | else () |
| 26 | in |
| 27 | case fromRep r of |
| 28 | NONE => bug "(isSome (fromRep r)) failed" |
| 29 | | SOME ii' => |
| 30 | if ii = ii' |
| 31 | then if r = toRep ii' |
| 32 | then () |
| 33 | else bug "(r = (toRep ii')) failed" |
| 34 | else bug "(ii = ii') failed" |
| 35 | end |
| 36 | |
| 37 | fun loop l = |
| 38 | case l of |
| 39 | nil => () |
| 40 | | (lo,hi)::l => |
| 41 | let |
| 42 | fun iloop ii = |
| 43 | if ii <= hi |
| 44 | then (checkToFrom ii; iloop (ii + 1)) |
| 45 | else loop l |
| 46 | in |
| 47 | iloop lo |
| 48 | end |
| 49 | |
| 50 | val tests = |
| 51 | let |
| 52 | val op + = SmallInt.+ |
| 53 | val op - = SmallInt.- |
| 54 | val op div = SmallInt.div |
| 55 | val two = SmallInt.fromInt 2 |
| 56 | val thirtytwo = SmallInt.fromInt 32 |
| 57 | val sixtyfour = thirtytwo + thirtytwo |
| 58 | |
| 59 | val min = valOf SmallInt.minInt |
| 60 | val hmin = min div two |
| 61 | val max = valOf SmallInt.maxInt |
| 62 | val hmax = max div two |
| 63 | in |
| 64 | [(SmallInt.toLarge min, SmallInt.toLarge (min + sixtyfour)), |
| 65 | (SmallInt.toLarge (hmin - thirtytwo), SmallInt.toLarge (hmin + thirtytwo)), |
| 66 | (SmallInt.toLarge (hmax - thirtytwo), SmallInt.toLarge (hmax + thirtytwo)), |
| 67 | (SmallInt.toLarge (max - sixtyfour), SmallInt.toLarge max)] |
| 68 | end |
| 69 | @ |
| 70 | let |
| 71 | val prec = valOf SmallInt.precision |
| 72 | val min = ~ (IntInf.pow (2, prec - 1)) |
| 73 | val hmin = min div 2 |
| 74 | val max = IntInf.pow (2, prec - 1) - 1 |
| 75 | val hmax = max div 2 |
| 76 | in |
| 77 | [(min, (min + 64)), |
| 78 | ((hmin - 32), (hmin + 32)), |
| 79 | ((hmax - 32), (hmax + 32)), |
| 80 | ((max - 64), max)] |
| 81 | end |
| 82 | |
| 83 | val () = loop tests |