Coder Social home page Coder Social logo

solidity-standard-library's Introduction

Quick overview of the library

Array.sol

Storage array wrapper.

UintArray contract members:

  • UintArray(uint[] data) - construct new array contract
  • min() - returns minimal array element
  • max() - returns maximal array element
  • sum() - returns sum of all array elements
  • set(uint[] arr) - assign array
  • get() - returns stored array
  • sort() - sorts all array elements

IntArray contract members:

  • IntArray(int[] data) - construct new array contract
  • min() - returns minimal array element
  • max() - returns maximal array element
  • sum() - returns sum of all array elements
  • set(int[] arr) - assign array
  • get() - returns stored array
  • sort() - sorts all array elements

Convert.sol

Helper contract to convert strings or ints/uints.

Converter contract members:

  • toString(uint x) - converts uint to string
  • toUint(string str) - converts string to uint

Math.sol

Basic mathematical functions.

Math contract members:

  • sqrt(uint x) - computes square root of x
  • mexp(uint x, uint k, uint m) - computes (pow(x, k)) mod m

Memory.sol

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 arr
  • m_unref_uint(uint ptr) - returns array pointed by ptr
  • m_ref_int(int[] arr) - returns address of arr
  • m_unref_int(uint ptr) - returns array pointed by ptr

Multiprecision.sol

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 representation
  • double_t(int integral, uint fractional) - creates a new double as integral.fractional
  • double_add(double a, double b) - a + b
  • double_sub(double a, double b) - a - b
  • double_mult(double a, double b) - aƗb
  • double_div(double a, double b) - a / b
  • double_lt(double a, double b) - a < b
  • double_le(double a, double b) - a <= b
  • double_eq(double a, double b) - a == b
  • double_ge(double a, double b) - a >= b
  • double_gt(double a, double b) - a > b

Random.sol

Random number generator based on SHA3 function (not cryptographicaly secure)

Random contract members

  • rand(uint seed) - returns random unsigned int generated wuth seed
  • randint() - returns random unsigned int
  • randbytes(uint size, uint seed) - returns array of random bytes

solidity-standard-library's People

Contributors

alianse777 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.