All Projects → dapphub → Ds Math

dapphub / Ds Math

Licence: gpl-3.0
Safe arithmetic

Programming Languages

solidity
1140 projects

Labels

Projects that are alternatives of or similar to Ds Math

Ergo
The Language for Smart Legal Contracts
Stars: ✭ 108 (-4.42%)
Mutual labels:  ethereum
Whitelist
whitelist.dock.io backend service
Stars: ✭ 111 (-1.77%)
Mutual labels:  ethereum
Eth Cli
CLI swiss army knife for Ethereum developers
Stars: ✭ 109 (-3.54%)
Mutual labels:  ethereum
Truffle Assertions
🛠 Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
Stars: ✭ 109 (-3.54%)
Mutual labels:  ethereum
Vscode Azure Blockchain Ethereum
Blockchain extension for VS Code
Stars: ✭ 111 (-1.77%)
Mutual labels:  ethereum
Awesome Solidity
A curated list of awesome Solidity resources
Stars: ✭ 111 (-1.77%)
Mutual labels:  ethereum
Learn Solidity With Examples
A repo full of smart contracts written in Solidity
Stars: ✭ 106 (-6.19%)
Mutual labels:  ethereum
Audit Checklist
A Solidity smart contract auditing checklist
Stars: ✭ 113 (+0%)
Mutual labels:  ethereum
Bokkypoobahsdatetimelibrary
Gas-Efficient Solidity DateTime Library
Stars: ✭ 111 (-1.77%)
Mutual labels:  ethereum
Hydro Scaffold Dex
A Decentralized Exchange Scaffold - launch a DEX in minutes
Stars: ✭ 112 (-0.88%)
Mutual labels:  ethereum
Eden Smart Contracts
EDEN - EDN Smart Token & Smart Contracts
Stars: ✭ 109 (-3.54%)
Mutual labels:  ethereum
Backend Ico Dashboard
Free & open-source dashboard for your next ICO, crowdsale or tokensale
Stars: ✭ 110 (-2.65%)
Mutual labels:  ethereum
Sputter
Ethereum Virtual Machine (EVM) implementation
Stars: ✭ 111 (-1.77%)
Mutual labels:  ethereum
Cryptotrader
This is an experimental trading bot framework written in PHP. It may contain bugs and should not be trusted with much money
Stars: ✭ 108 (-4.42%)
Mutual labels:  ethereum
Desktop
The official Musicoin Desktop Wallet Application
Stars: ✭ 112 (-0.88%)
Mutual labels:  ethereum
Truffle
A tool for developing smart contracts. Crafted with the finest cacaos.
Stars: ✭ 11,909 (+10438.94%)
Mutual labels:  ethereum
Geth Dev
A Docker Image to create a set of mining, local Ethereum nodes for development
Stars: ✭ 109 (-3.54%)
Mutual labels:  ethereum
Awesome Crowdsales
A curated list of ICO repositories that produced ERC20/ERC223 tokens
Stars: ✭ 113 (+0%)
Mutual labels:  ethereum
Ethereum Smart Contracts Security Checklist
Ethereum Smart Contracts Security CheckList From Knownsec 404 Team
Stars: ✭ 114 (+0.88%)
Mutual labels:  ethereum
Blockapi
A general framework for blockchain analytics
Stars: ✭ 111 (-1.77%)
Mutual labels:  ethereum

DSMath

Safe Arithmetic

DS-Math provides arithmetic functions for the common numerical primitive types of Solidity. You can safely add, subtract, multiply, and divide uint numbers without fear of integer overflow. You can also find the minimum and maximum of two numbers.

Additionally, this package provides arithmetic functions for new two higher level numerical concepts called wad (18 decimals) and ray (27 decimals). These are used to represent fixed-point decimal numbers.

A wad is a decimal number with 18 digits of precision and a ray is a decimal number with 27 digits of precision. These functions are necessary to account for the difference between how integer arithmetic behaves normally, and how decimal arithmetic should actually work. A brief example using wmul, which returns the product of a wad and another number:

1.1 * 2.2 == 2.42

//Regular integer arithmetic adds orders of magnitude:

110 * 220 == 24200

// Wad arithmetic does not add orders of magnitude:

wmul(1.1 ether, 2.2 ether) == 2.42 ether

Naming Convention

The standard functions are the uint set, so their function names are not prefixed: add, sub, mul, min, and max. There is no div function, as divide-by-zero checking is built into the Solidity compiler.

The int functions have an i prefix: imin, and imax.

Wad functions have a w prefix: wmul, wdiv.

Ray functions have a r prefix: rmul, rdiv, rpow.

API Reference

add

Return x + y or an exception in case of uint overflow.

sub

Return x - y or an exception in case of uint overflow.

mul

Return x * y or an exception in case of uint overflow.

min

Return the smaller number of x and y.

max

Return the larger number of x and y.

imin

Return the smaller number of x and y.

imax

Return the larger number of x and y.

wmul

Multiply two Wads and return a new Wad with the correct level of precision. A Wad is a decimal number with 18 digits of precision that is being represented as an integer.

wdiv

Divide two Wads and return a new Wad with the correct level of precision. A Wad is a decimal number with 18 digits of precision that is being represented as an integer.

rmul

Multiply two Rays and return a new Ray with the correct level of precision. A Ray is a decimal number with 27 digits of precision that is being represented as an integer.

rdiv

Divide two Rays and return a new Ray with the correct level of precision. A Ray is a decimal number with 27 digits of precision that is being represented as an integer.

rpow

Raise a Ray to the n^th power and return a new Ray with the correct level of precision. A Ray is a decimal number with 27 digits of precision that is being represented as an integer.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].