Storage array wrapper.
UintArray contract members:
UintArray(uint[] data)
- construct new array contractmin()
- returns minimal array elementmax()
- returns maximal array elementsum()
- returns sum of all array elementsset(uint[] arr)
- assign arrayget()
- returns stored arraysort()
- sorts all array elements
IntArray contract members:
IntArray(int[] data)
- construct new array contractmin()
- returns minimal array elementmax()
- returns maximal array elementsum()
- returns sum of all array elementsset(int[] arr)
- assign arrayget()
- returns stored arraysort()
- sorts all array elements
Helper contract to convert strings or ints/uints.
Converter contract members:
toString(uint x)
- converts uint to stringtoUint(string str)
- converts string to uint
Basic mathematical functions.
Math contract members:
sqrt(uint x)
- computes square root of xmexp(uint x, uint k, uint m)
- computes (pow(x, k)) mod m
WARNING: These functions are used to perform low-level memory access and may cause security risk when used improperly.
STDMemory contract members:
m_ref_uint(uint[] arr)
- returns address of arrm_unref_uint(uint ptr)
- returns array pointed by ptrm_ref_int(int[] arr)
- returns address of arrm_unref_int(uint ptr)
- returns array pointed by ptr
Floating point calculations. Note: double_t(1, 5) will be 1.05 but double_t(1, 50) will be 1.5 with dscale = 2 (Number of digits after dot)
Example:
import "multiprecision.sol";
contract Test is Double
{
function test() internal
{
double memory a = double_t(1, 20); // 1.20
double memory b = double_t(0, 2); // 0.02
double memory result = double_add(a, b); // 1.22
a = double_t(2, 0); // 2.00
b = double_t(1, 0); // 1.00
a.sign = true; // -2.00
result = double_add(a, b); // -2.00 + 1.00 = -1.00
result = double_sub(a, b); // -2.00 - 1.00 = -3.00
result = double_mult(a, b); // -2.00 * 1.00 = -2.00
result = double_div(a, b); // -2.00 / 1.00 = -2.00
dscale = 3; // change precision (.00 -> .000)
double_t(1, 5); // now 1.005
double_t(1, 50); // now 1.050
double_t(1, 500); // now 1.500
}
}
Double contract members:
struct double
- signed double representationdouble_t(int integral, uint fractional)
- creates a new double as integral.fractionaldouble_add(double a, double b)
- a + bdouble_sub(double a, double b)
- a - bdouble_mult(double a, double b)
- a×bdouble_div(double a, double b)
- a / bdouble_lt(double a, double b)
- a < bdouble_le(double a, double b)
- a <= bdouble_eq(double a, double b)
- a == bdouble_ge(double a, double b)
- a >= bdouble_gt(double a, double b)
- a > b
Random number generator based on SHA3 function (not cryptographicaly secure)
Random contract members
rand(uint seed)
- returns random unsigned int generated wuth seedrandint()
- returns random unsigned intrandbytes(uint size, uint seed)
- returns array of random bytes