Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonIntInf.adoc
1 MLtonIntInf
2 ===========
3
4 [source,sml]
5 ----
6 signature MLTON_INT_INF =
7 sig
8 type t = IntInf.int
9
10 val areSmall: t * t -> bool
11 val gcd: t * t -> t
12 val isSmall: t -> bool
13
14 structure BigWord : WORD
15 structure SmallInt : INTEGER
16 datatype rep =
17 Big of BigWord.word vector
18 | Small of SmallInt.int
19 val rep: t -> rep
20 val fromRep : rep -> t option
21 end
22 ----
23
24 MLton represents an arbitrary precision integer either as an unboxed
25 word with the bottom bit set to 1 and the top bits representing a
26 small signed integer, or as a pointer to a vector of words, where the
27 first word indicates the sign and the rest are the limbs of a
28 <:GnuMP:> big integer.
29
30 * `type t`
31 +
32 the same as type `IntInf.int`.
33
34 * `areSmall (a, b)`
35 +
36 returns true iff both `a` and `b` are small.
37
38 * `gcd (a, b)`
39 +
40 uses the <:GnuMP:GnuMP's> fast gcd implementation.
41
42 * `isSmall a`
43 +
44 returns true iff `a` is small.
45
46 * `BigWord : WORD`
47 +
48 representation of a big `IntInf.int` as a vector of words; on 32-bit
49 platforms, `BigWord` is likely to be equivalent to `Word32`, and on
50 64-bit platforms, `BigWord` is likely to be equivalent to `Word64`.
51
52 * `SmallInt : INTEGER`
53 +
54 representation of a small `IntInf.int` as a signed integer; on 32-bit
55 platforms, `SmallInt` is likely to be equivalent to `Int32`, and on
56 64-bit platforms, `SmallInt` is likely to be equivalent to `Int64`.
57
58 * `datatype rep`
59 +
60 the underlying representation of an `IntInf.int`.
61
62 * `rep i`
63 +
64 returns the underlying representation of `i`.
65
66 * `fromRep r`
67 +
68 converts from the underlying representation back to an `IntInf.int`.
69 If `fromRep r` is given anything besides the valid result of `rep i`
70 for some `i`, this function call will return `NONE`.