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