# ds-math: an innovative safe math library

Oct 19, 2017 · 3 min read

# Introduction of Wad and Ray for advanced decimal math

An unfortunate characteristic of the modern day Solidity compiler is that it doesn’t support fixed-point mathematics yet. Thus, it is not currently possible to represent the number 3.1415 natively. Most projects workaround this feature by representing their decimal numbers as unsigned integers and specifying the level of precision that is being used alongside it. An example:

// representing the number 121.234
uint tokenBalance = 1212340000000000000000
uint decimals = 18
Regular decimal arithmetic:1.1 * 2.2 = 2.42Regular integer arithmetic adds orders of magnitude:110 * 220 = 24200
Regular decimal arithmetic:1.1 * 2.2 = 2.42Regular integer arithmetic adds orders of magnitude:110 * 220 = 24200Wad arithmetic does not add orders of magnitude:wmul(1100000000000000000, 2200000000000000000) = 2420000000000000000

# Using this package

If you would like to use DS-Math in your project, we recommend that you install our command line developer tool called dapp and simply run these commands:

\$ dapp init
\$ dapp install ds-math

Written by