ForgeAbi v1.14.2 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

Link to this function

a + b View Source
(ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t() | number() | nil) +
  (ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t() | number() | nil) ::
  ForgeAbi.BigUint.t() | number()

Add two big int. Should return a BigUint.

iex> use ForgeAbi.Util.BigInt iex> biguint(1234) + biguint(1234) %ForgeAbi.BigUint{value: <<9, 164>>}

Link to this function

a - b View Source
(ForgeAbi.BigUint.t() | number()) -
  (ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t() | number()) ::
  ForgeAbi.BigUint.t() | number()

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>>}

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

Link to this function

bigsint(i) View Source
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}

Link to this function

biguint(i) View Source
biguint(integer() | nil) :: 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>>}

Link to this function

to_int(i) View Source
to_int(ForgeAbi.BigUint.t() | ForgeAbi.BigSint.t() | integer() | nil) ::
  integer()

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

Link to this function

to_sint(v) View Source
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}

Link to this function

to_uint(v) View Source
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>>}

Link to this function

to_unit(v, decimal \\ 0) View Source
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>>}