Biginteger library for SML (Standard ML) for doing integer operations on arbitrarily large integers.
It allows following integer operations(in the parenthesis, the corresponding function names are given)
- addition(add),
- subtraction(sub),
- multiplication(mul),
- division(div4bigint),
- mod(mod4bigint),
- comparisons:
- equal to?(eq)
- not equal to?(neq)
- less than?(lt)
- less than or equal to?(leq)
- greater than?(gt)
- greater than or equal to?(geq)
- Copy biginteger.sml to the folder where lies the test sml file (call it test.sml).
- Include the following line at the beginning of test.sml:
use "biginteger.sml";
- This library requires input in the form of string, instead of Integer (for the obvious reason that we want to do operations on integers of arbitrary length and int type of SML has a limit on its size). The string has to be converted to the biginteger type using
str2bi
function.
val a ="15" ;
val a_big = bigstruct.str2bi(a);
- Use any of the operations given in Operations supported like this:
val c_big = bigstruct.add(a_big,b_big);
where a_big
and b_big
are of biginteger type.
- Get back the string form from the biginteger form using
bi2str
function.
val c = bigstruct.bi2str(c_big);
All the functions take two biginteger as parameters. a $ b
is equivalent to biginteger.operation(a,b)
where operation
is any of the operations given in Operations supported and $
is the symbol of operation
. Note that a
and b
are of biginteger type. For example, to do a - b
, do biginteger.sub(a,b)
All the examples are here.