Is there a Java BigInt equivalent for Standard ML? The normal int type throws an exception when it overflows.
A:
The BigInt-equivalent is called LargeInt. See these lecture notes to see some functions on how to convert between int (aka Int) and LargeInt.
harms
2009-07-18 19:30:57
From the SML basis library: "If an implementation provides the `IntInf` structure, then `LargeInt` must be the same structure as `IntInf` (viewed through a thinning `INTEGER` signature). Otherwise, if `LargeInt` is not the same as `Int`, then there must be a structure `Int<N>` equal to `LargeInt`." In other words, `LargeInt` isn't guaranteed to be unbounded (though SML/NJ's is), but it's more portable than `IntInf` (which isn't required to exist).
ephemient
2009-07-18 20:05:14
I advise against using LargeInt. You'd much rather have a compile-time failure than an unexpected overflow at run time. (Although running out of memmory has a charm all its own.)
Norman Ramsey
2009-07-18 20:07:24