ForgeAbi v1.9.1 ForgeAbi.Util.BigInt View Source
Big int operators. Note that at the moment we only need :+
and :-
.
As for ==
, !=
, >
, >=
, <
, <=
the default behavior is as expected so
we won't override them.
Link to this section Summary
Functions
Add two big int. Should return a BigUint
Substract two big int. Should return a BigUint
Compare biguint, bigsint(we just use its abs value), and normal integer/float
Create a ForgeAbi.BigSint
Create a ForgeAbi.BigUint
Convert BigInt to integer
Convert a uint to sint
Convert a sint to uint
Generate a BigSint with a regular integer
Link to this section Functions
Add two big int. Should return a BigUint.
iex> use ForgeAbi.Util.BigInt iex> biguint(1234) + biguint(1234) %ForgeAbi.BigUint{value: <<9, 164>>}
Substract two big int. Should return a BigUint.
iex> use ForgeAbi.Util.BigInt iex> biguint(1234) - biguint(1233) %ForgeAbi.BigUint{value: <<1>>} iex> biguint(1234) - biguint(1235) %ForgeAbi.BigUint{value: <<0>>} iex> biguint(1234) - bigsint(-1235) %ForgeAbi.BigUint{value: <<9, 165>>} iex> bigsint(-1234) - biguint(1235) %ForgeAbi.BigUint{value: <<0>>}
a <= b View Source
a >= b View Source
Compare biguint, bigsint(we just use its abs value), and normal integer/float
iex> use ForgeAbi.Util.BigInt iex> biguint(1234) > biguint(1233) true iex> biguint(1234) <= biguint(1235) true iex> biguint(1234) > bigsint(-1235) false iex> bigsint(-1234) > biguint(100) true iex> bigsint(-1234) > 1000 true iex> bigsint(-1234) > 2000 false iex> 1000 >= biguint(999) true iex> 1000 >= biguint(1001) false
bigsint(i)
View Source
bigsint(integer()) :: ForgeAbi.BigSint.t()
bigsint(integer()) :: ForgeAbi.BigSint.t()
Create a ForgeAbi.BigSint
.
iex> use ForgeAbi.Util.BigInt iex> bigsint(1234) %ForgeAbi.BigSint{value: <<4, 210>>, minus: false} iex> bigsint(-1234) %ForgeAbi.BigSint{value: <<4, 210>>, minus: true} iex> bigsint(-1111111111111111111111111111111111111111) %ForgeAbi.BigSint{value: <<3, 67, 232, 55, 78, 152, 132, 21, 75, 248, 55, 181, 113, 199, 28, 113, 199>>, minus: true}
biguint(i)
View Source
biguint(integer()) :: ForgeAbi.BigUint.t()
biguint(integer()) :: ForgeAbi.BigUint.t()
Create a ForgeAbi.BigUint
.
iex> use ForgeAbi.Util.BigInt iex> biguint(1234) %ForgeAbi.BigUint{value: <<4, 210>>} iex> biguint(1111111111111111111111111111111111111111) %ForgeAbi.BigUint{value: <<3, 67, 232, 55, 78, 152, 132, 21, 75, 248, 55, 181, 113, 199, 28, 113, 199>>}
one_token(decimal \\ 0)
View Source
one_token(non_neg_integer()) :: non_neg_integer()
one_token(non_neg_integer()) :: non_neg_integer()
to_int(i) View Source
Convert BigInt to integer
iex> use ForgeAbi.Util.BigInt iex> to_int(biguint(1)) === 1 true iex> to_int(bigsint(1)) === 1 true iex> to_int(bigsint(-1)) === 1 false
to_sint(v)
View Source
to_sint(ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t()) :: ForgeAbi.BigSint.t()
to_sint(ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t()) :: ForgeAbi.BigSint.t()
Convert a uint to sint
iex> use ForgeAbi.Util.BigInt iex> to_sint(bigsint(-1234)) %ForgeAbi.BigSint{value: <<4, 210>>, minus: true} iex> to_sint(biguint(1234)) %ForgeAbi.BigSint{value: <<4, 210>>, minus: false}
to_uint(v)
View Source
to_uint(ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t() | nil) ::
ForgeAbi.BigUint.t()
to_uint(ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t() | nil) :: ForgeAbi.BigUint.t()
Convert a sint to uint
iex> use ForgeAbi.Util.BigInt iex> to_uint(bigsint(-1234)) %ForgeAbi.BigUint{value: <<4, 210>>} iex> to_uint(biguint(1234)) %ForgeAbi.BigUint{value: <<4, 210>>}
to_unit(v, decimal \\ 0)
View Source
to_unit(integer(), non_neg_integer()) :: ForgeAbi.BigSint.t()
to_unit(integer(), non_neg_integer()) :: ForgeAbi.BigSint.t()
Generate a BigSint with a regular integer
iex> use ForgeAbi.Util.BigInt iex> to_unit(-1234) %ForgeAbi.BigSint{minus: true, value: <<171, 64, 124, 158, 176, 82, 0, 0>>} iex> to_unit(200) %ForgeAbi.BigSint{minus: false, value: <<27, 193, 109, 103, 78, 200, 0, 0>>}