Solidity Floating Point Library

Not only does BANKEX work on commercial projects, we are pleased to develop useful products for other crypto developers as well.

One of those projects is our non-profit product — Floating point library for Solidity.

What is it?

Floating point is a method of representing real numbers and is a main computer format for this representation.

Solidity is a contract-oriented programming language for writing smart contracts on Ethereum.

Why is this necessary?

At the current state of the Ethereum platform one can not represent the number 0.58 without using some implicit divisor (like 1000000 == 1.000000, method used by all ERC20 tokens).

This expands the functionality of smart contracts written in the language of Solidity.

Why do we implement float point type in the first place: we believe that at some point, float point operations will be necessary to be implemented in solidity. For example a “Decimal” data type is necessary for conducting financial operations and the experience gained during the creation of float type can be transferred (“Decimal” is a format of representing real numbers with up to some defined amount of decimal digits after decimal point with some extra rounding rules).

What's inside:

Crude core for library and set of tests, including helper functions to encode BigNumber into bytes32. Library is in a form of contract for ease of development.

For the initial public release, we focus on the basic functions that are necessary for further implementations of standard math library.

This version includes:

  1. Encoding and decoding of packed 256 bit representation (in a form of bytes32 base type) to intermediate representation of three unsigned 256 bit integers for sign, mantissa and exponent. Intermediate representation is more convenient for basic operations such as addition.
  2. Addition, subtraction, multiplication and naive division.
  3. Fast inverse square root and fast division.
  4. Log2 function.

Implementation of floating point number will expand capabilities of Ethereum in terms of more general and convenient calculations (and get rid of artificial decimal multipliers). Don’t forget about the convenience — we are used to work with numbers containing decimal point.

And finally — for the precision of calculations in the financial world special “Decimal” data type is traditionally used, and the experience of implementing floating point numbers can be transferred to this type as well.