{"id":20460449,"url":"https://github.com/dapphub/ds-math","last_synced_at":"2025-04-07T05:11:05.781Z","repository":{"id":45004678,"uuid":"86636287","full_name":"dapphub/ds-math","owner":"dapphub","description":"Safe arithmetic","archived":false,"fork":false,"pushed_at":"2022-07-29T06:41:05.000Z","size":50,"stargazers_count":274,"open_issues_count":7,"forks_count":65,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-30T21:10:26.102Z","etag":null,"topics":["arithmetic","dappsys","ethereum","solidity"],"latest_commit_sha":null,"homepage":"https://dapp.tools/dappsys/ds-math.html","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dapphub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-29T22:49:28.000Z","updated_at":"2025-02-23T06:28:07.000Z","dependencies_parsed_at":"2022-08-04T01:30:47.931Z","dependency_job_id":null,"html_url":"https://github.com/dapphub/ds-math","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapphub%2Fds-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapphub%2Fds-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapphub%2Fds-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapphub%2Fds-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dapphub","download_url":"https://codeload.github.com/dapphub/ds-math/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic","dappsys","ethereum","solidity"],"created_at":"2024-11-15T12:19:38.572Z","updated_at":"2025-04-07T05:11:05.754Z","avatar_url":"https://github.com/dapphub.png","language":"Solidity","readme":"\u003ch2\u003eDSMath\n  \u003csmall class=\"text-muted\"\u003e\n    \u003ca href=\"https://github.com/dapphub/ds-math\"\u003e\u003cspan class=\"fa fa-github\"\u003e\u003c/span\u003e\u003c/a\u003e\n  \u003c/small\u003e\n\u003c/h2\u003e\n\n_Safe Arithmetic_\n\nDS-Math provides arithmetic functions for the common numerical primitive types\n of Solidity. You can safely add, subtract, multiply, and divide `uint` numbers \nwithout fear of integer overflow. You can also find the minimum and maximum of \ntwo numbers.\n\nAdditionally, this package provides arithmetic functions for new two higher \nlevel numerical concepts called wad (18 decimals) and ray (27 decimals). These \nare used to represent fixed-point decimal numbers. \n\nA wad is a decimal number with 18 digits of precision and a ray is a decimal \nnumber with 27 digits of precision. These functions are necessary to account for \nthe difference between how integer arithmetic behaves normally, and how decimal \narithmetic should actually work. A brief example using `wmul`, which returns the \nproduct of a wad and another number:\n\n```solidity\n1.1 * 2.2 == 2.42\n\n//Regular integer arithmetic adds orders of magnitude:\n\n110 * 220 == 24200\n\n// Wad arithmetic does not add orders of magnitude:\n\nwmul(1.1 ether, 2.2 ether) == 2.42 ether\n```\n\n### Naming Convention\n\nThe standard functions are the `uint` set, so their function names are not \nprefixed: `add`, `sub`, `mul`, `min`, and `max`. There is no `div` function, as \ndivide-by-zero checking is built into the Solidity compiler.\n\nThe `int` functions have an `i` prefix: `imin`, and `imax`.\n\nWad functions have a `w` prefix: `wmul`, `wdiv`.\n\nRay functions have a `r` prefix: `rmul`, `rdiv`, `rpow`.\n\n### API Reference\n\n#### `add`\nReturn `x + y` or an exception in case of `uint` overflow.\n\n#### `sub`\nReturn `x - y` or an exception in case of `uint` overflow.\n\n#### `mul`\nReturn `x * y` or an exception in case of `uint` overflow.\n\n#### `min`\nReturn the smaller number of `x` and  `y`.\n\n#### `max`\nReturn the larger number of `x` and  `y`.\n\n#### `imin`\nReturn the smaller number of `x` and  `y`.\n\n#### `imax`\nReturn the larger number of `x` and  `y`.\n\n#### `wmul`\nMultiply two Wads and return a new Wad with the correct level of precision. A \nWad is a decimal number with 18 digits of precision that is being represented \nas an integer.\n\n#### `wdiv`\nDivide two Wads and return a new Wad with the correct level of precision. A \nWad is a decimal number with 18 digits of precision that is being represented \nas an integer.\n\n#### `rmul`\nMultiply two Rays and return a new Ray with the correct level of precision. A \nRay is a decimal number with 27 digits of precision that is being represented \nas an integer.\n\n#### `rdiv`\nDivide two Rays and return a new Ray with the correct level of precision. A \nRay is a decimal number with 27 digits of precision that is being represented \nas an integer.\n\n#### `rpow`\nRaise a Ray to the n^th power and return a new Ray with the correct level of \nprecision. A Ray is a decimal number with 27 digits of precision that is being \nrepresented as an integer.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapphub%2Fds-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdapphub%2Fds-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapphub%2Fds-math/lists"}