Practical overview
When it fits
Use DSMath when Solidity contract logic needs the documented checked integer operations or fixed-point wad and ray helpers.
Who it is for
- Solidity developers implementing arithmetic in smart contracts.
- Contract authors working with fixed-point values represented as integers.
Documented uses
- Add, subtract, and multiply unsigned integers with overflow exceptions.
- Compare signed or unsigned integers using minimum and maximum helpers.
- Multiply and divide wad or ray values while retaining their documented precision.
- Raise a ray value to a power.
Requirements & limits
The repository is public and identifies its license as GPL-3.0.
- Wads represent fixed-point values with 18 decimal places; rays use 27.
- Unsigned add, subtract, and multiply return an exception on overflow.
- The library documents no separate uint division helper; its README attributes division-by-zero checking to the Solidity compiler.
- The documented ray operations include exponentiation, while the wad operations listed are multiplication and division.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Choose DS-Math operations for Solidity values
Use the documented integer and fixed-point arithmetic functions in Solidity contract logic.
Before you start
- A Solidity contract using unsigned integer, signed integer min/max, wad, or ray values.
- The DS-Math function names and behaviors described in the project README.
Steps
For checked unsigned integer arithmetic, use
add,sub, ormul; these return an exception on overflow.For comparisons, use
minormaxfor unsigned values, oriminorimaxfor signed values.For 18-decimal fixed-point values, use
wmulorwdiv; for 27-decimal values, usermul,rdiv, orrpow.Keep wad and ray operands in their corresponding fixed-point representation so the functions preserve the documented precision.
Expected outcome
Contract logic can use the documented checked arithmetic, min/max, and wad/ray fixed-point operations.
Guide limitations
- The README documents no unsigned
divfunction; it says Solidity provides divide-by-zero checking. - This guidance describes function selection, not installation, compilation, or testing.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 15 October 2026
- Original website title
- dapphub/ds-math · Official homepage title · retained in its source language

