77[ license ] : https://opensource.org/licenses/MIT
88[ license-badge ] : https://img.shields.io/badge/License-MIT-blue.svg
99
10+ <div align =" center " >
11+ <img src =" ./assets/logo.png " alt =" PRBMath Logo " width =" 250 " >
12+ </div >
13+
1014** Solidity library for advanced fixed-point math** that operates with signed 59.18-decimal fixed-point and unsigned 60.18-decimal fixed-point numbers.
1115The name of the number format comes from the integer part having up to 59 digits for signed numbers and 60 digits for unsigned numbers, while the
1216fractional part has up to 18 decimals. The numbers are bound by the minimum and the maximum values permitted by the Solidity types int256 and uint256.
@@ -21,15 +25,15 @@ fractional part has up to 18 decimals. The numbers are bound by the minimum and
2125- Well-documented with NatSpec comments
2226- Built and tested with Foundry
2327
24- I created this because I wanted a fixed-point math library that is at the same time intuitive, efficient and safe. I looked at
25- [ ABDKMath64x64 ] ( https://github.com/abdk-consulting/abdk-libraries-solidity ) , which is fast, but it uses binary numbers which are counter-intuitive and
26- non-familiar to humans. Then, I looked at [ Fixidity ] ( https://github.com/CementDAO/Fixidity ) , which operates with denary numbers and has wide
27- precision, but is slow and susceptible to phantom overflow. Finally, I looked at [ Solmate ] ( https://github.com/transmissions11/solmate ) , which checks
28- all the boxes mentioned thus far , but it doesn't offer type safety.
28+ > [ !NOTE ]
29+ >
30+ > PRBMath is a fixed-point math library that is at the same time intuitive, efficient and safe.
31+ > [ ABDKMath64x64 ] ( https://github.com/abdk-consulting/abdk-libraries-solidity ) is fast, but uses binary numbers, which are counter-intuitive.
32+ > [ Solmate ] ( https://github.com/transmissions11/solmate ) is fast and intuitive , but lacks type safety.
2933
30- ## Install
34+ ## 📦 Install
3135
32- ### Node.js
36+ ### 🟢 Node.js
3337
3438This is the recommended approach.
3539
@@ -45,7 +49,7 @@ Then, if you are using Foundry, you need to add this to your `remappings.txt` fi
4549@prb/math/=node_modules/@prb/math/
4650```
4751
48- ### Git Submodules
52+ ### 🔗 Git Submodules
4953
5054This installation method is not recommended, but it is available for those who prefer it.
5155
@@ -70,7 +74,7 @@ Finally, add this to your `remappings.txt` file:
7074@prb/math/=lib/prb-math/
7175```
7276
73- ## Usage
77+ ## 🚀 Usage
7478
7579There are two user-defined value types:
7680
@@ -84,7 +88,7 @@ If you don't need negative numbers, there's no point in using the signed flavor
8488Note that PRBMath is not a library in the Solidity [ sense] ( https://docs.soliditylang.org/en/v0.8.17/contracts.html#libraries ) . It's just a collection
8589of free functions.
8690
87- ### Importing
91+ ### 📥 Importing
8892
8993It is recommended that you import PRBMath using specific symbols. Importing full files can result in Solidity complaining about duplicate definitions
9094and static analyzers like Slither erroring, especially as repos grow and have more dependencies with overlapping names.
@@ -107,7 +111,7 @@ import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";
107111
108112Note that PRBMath can only be used in Solidity v0.8.19 and above.
109113
110- ### SD59x18
114+ ### ➕ SD59x18
111115
112116``` solidity
113117// SPDX-License-Identifier: UNLICENSED
@@ -131,7 +135,7 @@ contract SignedConsumer {
131135}
132136```
133137
134- ### UD60x18
138+ ### ➕ UD60x18
135139
136140``` solidity
137141// SPDX-License-Identifier: UNLICENSED
@@ -155,12 +159,12 @@ contract UnsignedConsumer {
155159}
156160```
157161
158- ## Features
162+ ## ✨ Features
159163
160164Because there's significant overlap between the features available in SD59x18 and UD60x18, there is only one table per section. If in doubt, refer to
161165the source code, which is well-documented with NatSpec comments.
162166
163- ### Mathematical Functions
167+ ### 🔢 Mathematical Functions
164168
165169| Name | Operator | Description |
166170| ------- | -------- | ------------------------------------------------ |
@@ -182,7 +186,7 @@ the source code, which is well-documented with NatSpec comments.
182186| ` powu ` | N/A | Power function x^y with y simple integer |
183187| ` sqrt ` | N/A | Square root |
184188
185- ### Adjacent Value Types
189+ ### 🔗 Adjacent Value Types
186190
187191PRBMath provides adjacent value types that serve as abstractions over other vanilla types:
188192
@@ -198,7 +202,7 @@ These are useful if you want to save gas by using a lower bit width integer, e.g
198202Note that these types don't have any mathematical functionality. To do math with them, you will have to unwrap them into a simple integer and then to
199203the core types ` SD59x18 ` and ` UD60x18 ` .
200204
201- ### Casting Functions
205+ ### 🔄 Casting Functions
202206
203207All PRBMath types have casting functions to and from all other types, including a few basic types like ` uint128 ` and ` uint40 ` .
204208
@@ -216,7 +220,7 @@ All PRBMath types have casting functions to and from all other types, including
216220| ` ud2x18 ` | Alias for ` UD2x18.wrap ` |
217221| ` ud60x18 ` | Alias for ` UD60x18.wrap ` |
218222
219- ### Conversion Functions
223+ ### ⚡ Conversion Functions
220224
221225The difference between "conversion" and "casting" is that conversion functions multiply or divide the inputs, whereas casting functions simply cast
222226them.
@@ -228,7 +232,7 @@ them.
228232| ` convert(int256) ` | Converts a simple integer to SD59x18 by multiplying it by 1e18 |
229233| ` convert(uint256) ` | Converts a simple integer to UD60x18 type by multiplying it by 1e18 |
230234
231- ### Helper Functions
235+ ### 🛠️ Helper Functions
232236
233237In addition to offering mathematical, casting, and conversion functions, PRBMath provides numerous helper functions for user-defined value types:
234238
@@ -274,7 +278,7 @@ function addRshiftEq() pure returns (bool result) {
274278
275279```
276280
277- ### Assertions
281+ ### ✅ Assertions
278282
279283PRBMath comes with typed assertions that you can use for writing tests with [ PRBTest] ( https://github.com/PaulRBerg/prb-test ) , which is based on
280284Foundry. This is useful if, for example, you would like to assert that two UD60x18 numbers are equal.
@@ -296,7 +300,7 @@ contract MyTest is PRBTest, PRBMathAssertions {
296300}
297301```
298302
299- ## Gas Efficiency
303+ ## ⚡ Gas Efficiency
300304
301305PRBMath is faster than ABDKMath for ` abs ` , ` exp ` , ` exp2 ` , ` gm ` , ` inv ` , ` ln ` , ` log2 ` , but it is slower than ABDKMath for ` avg ` , ` div ` , ` mul ` , ` powu `
302306and ` sqrt ` .
@@ -351,12 +355,12 @@ Gas estimations based on the v3.0 release of ABDKMath. See my [abdk-gas-estimati
351355| pow | 303 | 4740 | 1792 |
352356| sqrt | 129 | 809 | 699 |
353357
354- ## Contributing
358+ ## 🤝 Contributing
355359
356360Feel free to dive in! [ Open] ( https://github.com/PaulRBerg/prb-math/issues/new ) an issue,
357361[ start] ( https://github.com/PaulRBerg/prb-math/discussions/new ) a discussion or submit a PR.
358362
359- ### Pre Requisites
363+ ### 📋 Pre Requisites
360364
361365You will need the following software on your machine:
362366
@@ -367,7 +371,7 @@ You will need the following software on your machine:
367371
368372In addition, familiarity with [ Solidity] ( https://soliditylang.org/ ) is requisite.
369373
370- ### Set Up
374+ ### ⚙️ Set Up
371375
372376Clone this repository including submodules:
373377
@@ -383,35 +387,45 @@ $ bun install
383387
384388Now you can start making changes.
385389
386- ### Syntax Highlighting
390+ ### 🎨 Syntax Highlighting
387391
388392You will need the following VSCode extensions:
389393
390394- [ hardhat-solidity] ( https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity )
391395- [ vscode-tree-language] ( https://marketplace.visualstudio.com/items?itemName=CTC.vscode-tree-extension )
392396
393- ## Security
397+ ## 🔒 Security
394398
395399The codebase has undergone audits by leading security experts from Cantina and Certora. For a comprehensive list of all audits conducted, see the
396400[ SECURITY] ( ./SECURITY.md ) file.
397401
398- ### Caveat Emptor
402+ ### ⚠️ Caveat Emptor
399403
400404This is experimental software and is provided on an "as is" and "as available" basis. I do not give any warranties and will not be liable for any
401405loss, direct or indirect through continued use of this codebase.
402406
403- ### Contact
407+ ### 📞 Contact
404408
405409If you discover any bugs or security issues, please report them via [ Telegram] ( https://t.me/PaulRBerg ) .
406410
407- ## Acknowledgments
411+ ## 🙏 Acknowledgments
408412
409413- Mikhail Vladimirov for the insights he shared in the [ Math in Solidity] ( https://medium.com/coinmonks/math-in-solidity-part-1-numbers-384c8377f26d )
410414 article series.
411415- Remco Bloemen for his work on [ overflow-safe multiplication and division] ( https://xn--2-umb.com/21/muldiv/ ) , and for responding to the questions I
412416 asked him while developing the library.
413417- Everyone who has contributed a PR to this repository.
414418
415- ## License
419+ <h2 >
420+ <img src="./assets/op.png"
421+ alt="Optimism logo"
422+ width="23" />
423+ Retro Funding
424+ </h2 >
425+
426+ A big shoutout and thank you to the [ Optimism] ( https://optimism.io ) team for funding the development of this library via the
427+ [ Retro Funding] ( https://atlas.optimism.io/project/0x7e917a2d0718401c9fe2a82f43ea558f5128f251b1e658c76dc7ff9a5e9fd993 ) program.
428+
429+ ## 📄 License
416430
417431This project is licensed under MIT.
0 commit comments