evm v0.1.14 MathHelper
Simple functions to help with common math functions.
Link to this section Summary
Functions
Bits to words
Simple floor function that makes sure we return an integer type
Returns the byte size of an integer
Simple helper to calculate a log in any
given base. E.g. the log_15(30)
, which
would be expressed at MathHelper.log(30, 15)
Simple round function
Link to this section Functions
Bits to words
Examples
iex> MathHelper.bits_to_words(0)
0
iex> MathHelper.bits_to_words(9)
1
iex> MathHelper.bits_to_words(256)
8
Simple floor function that makes sure we return an integer type.
Examples
iex> MathHelper.floor(3.5)
3
iex> MathHelper.floor(-3.5)
-4
iex> MathHelper.floor(5)
5
Returns the byte size of an integer
Examples
iex> MathHelper.integer_byte_size(0)
0
iex> MathHelper.integer_byte_size(1)
1
iex> MathHelper.integer_byte_size(0xfffffffff)
5
Simple helper to calculate a log in any
given base. E.g. the log_15(30)
, which
would be expressed at MathHelper.log(30, 15)
.
Examples
iex> MathHelper.log(225, 15)
2.0
iex> MathHelper.log(240, 15)
2.0238320992392618
iex> MathHelper.log(1024, 10)
3.0102999566398116
iex> MathHelper.log(999999, 9999)
1.500016178459417
Link to this function
round_int(n)
Simple round function
Examples
iex> MathHelper.round_int(3.5)
3
iex> MathHelper.round_int(-3.5)
-3
iex> MathHelper.round_int(-0.5)
0