signature MLTON_INT_INF =
sig
type t = IntInf.int
val areSmall: t * t -> bool
val gcd: t * t -> t
val isSmall: t -> bool
structure BigWord : WORD
structure SmallInt : INTEGER
datatype rep =
Big of BigWord.word vector
| Small of SmallInt.int
val rep: t -> rep
val fromRep : rep -> t option
end
MLton represents an arbitrary precision integer either as an unboxed word with the bottom bit set to 1 and the top bits representing a small signed integer, or as a pointer to a vector of words, where the first word indicates the sign and the rest are the limbs of a GMP big integer.
-
type tthe same as type
IntInf.int. -
areSmall (a, b)returns true iff both
aandbare small. -
gcd (a, b)uses GMP’s fast gcd implementation.
-
isSmall areturns true iff
ais small. -
BigWord : WORDrepresentation of a big
IntInf.intas a vector of words; on 32-bit platforms,BigWordis likely to be equivalent toWord32, and on 64-bit platforms,BigWordis likely to be equivalent toWord64. -
SmallInt : INTEGERrepresentation of a small
IntInf.intas a signed integer; on 32-bit platforms,SmallIntis likely to be equivalent toInt32, and on 64-bit platforms,SmallIntis likely to be equivalent toInt64. -
datatype repthe underlying representation of an
IntInf.int. -
rep ireturns the underlying representation of
i. -
fromRep rconverts from the underlying representation back to an
IntInf.int. IffromRep ris given anything besides the valid result ofrep ifor somei, this function call will returnNONE.