Socket
Socket
Sign inDemoInstall

@prb/math

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 3.3.0

src/casting/Uint128.sol

266

CHANGELOG.md

@@ -8,23 +8,45 @@ # Changelog

[3.2.0]: https://github.com/paulrberg/prb-math/compare/v3.1.0...v3.2.0
[3.1.0]: https://github.com/paulrberg/prb-math/compare/v3.0.0...v3.1.0
[3.0.0]: https://github.com/paulrberg/prb-math/compare/v2.5.0...v3.0.0
[2.5.0]: https://github.com/paulrberg/prb-math/compare/v2.4.3...v2.5.0
[2.4.3]: https://github.com/paulrberg/prb-math/compare/v2.4.2...v2.4.3
[2.4.2]: https://github.com/paulrberg/prb-math/compare/v2.4.1...v2.4.2
[2.4.1]: https://github.com/paulrberg/prb-math/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/paulrberg/prb-math/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/paulrberg/prb-math/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/paulrberg/prb-math/compare/v2.1.0...v2.2.0
[2.1.0]: https://github.com/paulrberg/prb-math/compare/v2.0.1...v2.1.0
[2.0.1]: https://github.com/paulrberg/prb-math/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/paulrberg/prb-math/compare/v1.1.0...v2.0.0
[1.1.0]: https://github.com/paulrberg/prb-math/compare/v1.0.5...v1.1.0
[1.0.5]: https://github.com/paulrberg/prb-math/compare/v1.0.4...v1.0.5
[1.0.4]: https://github.com/paulrberg/prb-math/compare/v1.0.3...v1.0.4
[1.0.3]: https://github.com/paulrberg/prb-math/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/paulrberg/prb-math/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/paulrberg/prb-math/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/paulrberg/prb-math/releases/tag/v1.0.0
[3.3.0]: https://github.com/PaulRBerg/prb-math/compare/v3.2.0...v3.3.0
[3.2.0]: https://github.com/PaulRBerg/prb-math/compare/v3.1.0...v3.2.0
[3.1.0]: https://github.com/PaulRBerg/prb-math/compare/v3.0.0...v3.1.0
[3.0.0]: https://github.com/PaulRBerg/prb-math/compare/v2.5.0...v3.0.0
[2.5.0]: https://github.com/PaulRBerg/prb-math/compare/v2.4.3...v2.5.0
[2.4.3]: https://github.com/PaulRBerg/prb-math/compare/v2.4.2...v2.4.3
[2.4.2]: https://github.com/PaulRBerg/prb-math/compare/v2.4.1...v2.4.2
[2.4.1]: https://github.com/PaulRBerg/prb-math/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/PaulRBerg/prb-math/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/PaulRBerg/prb-math/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/PaulRBerg/prb-math/compare/v2.1.0...v2.2.0
[2.1.0]: https://github.com/PaulRBerg/prb-math/compare/v2.0.1...v2.1.0
[2.0.1]: https://github.com/PaulRBerg/prb-math/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/PaulRBerg/prb-math/compare/v1.1.0...v2.0.0
[1.1.0]: https://github.com/PaulRBerg/prb-math/compare/v1.0.5...v1.1.0
[1.0.5]: https://github.com/PaulRBerg/prb-math/compare/v1.0.4...v1.0.5
[1.0.4]: https://github.com/PaulRBerg/prb-math/compare/v1.0.3...v1.0.4
[1.0.3]: https://github.com/PaulRBerg/prb-math/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/PaulRBerg/prb-math/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/PaulRBerg/prb-math/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/PaulRBerg/prb-math/releases/tag/v1.0.0
## [3.3.0] - 2023-02-06
### Changed
- Improve documentation (@PaulRBerg)
- Improve names of custom errors and functions (@PaulRBerg)
- Optimize assembly usage by annotating assembly blocks with the "memory-safe" dialect (@PaulRBerg)
- Modularize code by splitting it into multiple categories: casting, constants, conversions, errors, helpers, math, and value types (@PaulRBerg)
- Rename `Assertions` to `PRBMathAssertions` in a backward-compatible way (@PaulRBerg)
- Upgrade Node.js package dependencies (@PaulRBerg)
### Added
- Add casting utilities for PRBMath types and `uint128` and `uint40` (@PaulRBerg)
- Add more constants in `SD1x18` and `UD2x18` (@PaulRBerg)
- Add `PRBMathUtils` contract with test utils (@PaulRBerg)
- Add test assertions overloads with `err` param (@PaulRBerg)
- Add typed versions of `bound` test util (@PaulRBerg)
- Add `wrap` and `unwrap` in `SD1x18` and `UD2x18` (@PaulRBerg)
- Expose `unwrap` via `using for ... global` (@PaulRBerg)
## [3.2.0] - 2022-12-13

@@ -34,11 +56,11 @@

- Add assertions for array comparisons (@paulrberg)
- Add assertions for array comparisons (@PaulRBerg)
### Removed
- Delete assertions that have an "err" argument (@paulrberg)
- Delete assertions that have an "err" argument (@PaulRBerg)
### Fixed
- Match types for `SD1x18` and `UD2x18` assertions (@paulrberg)
- Match types for `SD1x18` and `UD2x18` assertions (@PaulRBerg)

@@ -49,50 +71,50 @@ ## [3.1.0] - 2022-12-13

- Add value types `SD1x18` and `UD2x18` (@paulrberg)
- Add value types `SD1x18` and `UD2x18` (@PaulRBerg)
## [3.0.0] - 2022-11-29
[1b82ea]: https://github.com/paulrberg/prb-math/commit/1b82ea
[a69b4b]: https://github.com/paulrberg/prb-math/commit/a69b4b
[1b82ea]: https://github.com/PaulRBerg/prb-math/commit/1b82ea
[a69b4b]: https://github.com/PaulRBerg/prb-math/commit/a69b4b
### Changed
- **Breaking:** Refactor the libraries into free functions and user defined value types ([`a69b4b`][a69b4b]) (@paulrberg)
- **Breaking:** Set minimum compiler pragma to `>=0.8.13` ([`a69b4b`][a69b4b]) (@paulrberg)
- **Breaking:** Rename `SCALE` to `UNIT` ([`4d3658`](https://github.com/paulrberg/prb-math/commit/4d3658)) (@paulrberg)
- Always truncate instead of rounding down in multiplication functions ([21fb32](https://github.com/paulrberg/prb-math/commit/21fb32)) (@paulrberg)
- Change license to MIT (@paulrberg)
- Check if `y` is zero in `gm` ([`5b585c`](https://github.com/paulrberg/prb-math/commit/5b585c)) (@paulrberg)
- Optimize `avg` by using the SWAR technique ([#89](https://github.com/paulrberg/prb-math/pull/89)) (@paulrberg)
- Optimize `div` and `mulDivSigned` by wrapping unary operations in unchecked blocks ([`a69b4b`][a69b4b]) (@paulrberg)
- Optimize `exp2` by batching bit checks ([#77](https://github.com/paulrberg/prb-math/pull/77)) (@k06a)
- Optimize `msb` by using assembly ([#135](https://github.com/paulrberg/prb-math/pull/135)) (@t4sk, @paulrberg)
- Optimize result assignment in `powu` ([673802](https://github.com/paulrberg/prb-math/commit/673802)) (@paulrberg)
- Rename `fromInt` to `toSD59x18` and `toInt` to `fromSD59x18` ([`a69b4b`][a69b4b]) (@paulrberg)
- Rename `fromUint` to `toUD60x18` and `toUint` to `fromUD60x18` ([`a69b4b`][a69b4b]) (@paulrberg)
- Rename `mostSignificantBit` to `msb` ([`a69b4b`][a69b4b]) (@paulrberg)
- Rename `mulDivFixedPoint` to `mulDiv18` ([`4c5430`](https://github.com/paulrberg/prb-math/commit/4c5430)) (@paulrberg)
- Rename `PRBMath.sol` to `Core.sol` ([`1b82ea`][1b82ea]) (@paulrberg)
- Rename shared `sqrt` in `prbSqrt` ([`1b82ea`][1b82ea]) (@paulrberg)
- Rename shared `exp2` in `prbExp2` ([`1b82ea`][1b82ea]) (@paulrberg)
- Revert with inputs instead of computed value custom errors (@paulrberg)
- Return base if exponent is one in `pow` ([`977d43`](https://github.com/paulrberg/prb-math/commit/977d43)) (@paulrberg)
- Format mathematical expressions using LaTeX (@paulrberg)
- Improve wording and formatting in comments, NatSpec documentation, and README (@paulrberg)
- **Breaking:** Refactor the libraries into free functions and user defined value types ([`a69b4b`][a69b4b]) (@PaulRBerg)
- **Breaking:** Set minimum compiler pragma to `>=0.8.13` ([`a69b4b`][a69b4b]) (@PaulRBerg)
- **Breaking:** Rename `SCALE` to `UNIT` ([`4d3658`](https://github.com/PaulRBerg/prb-math/commit/4d3658)) (@PaulRBerg)
- Always truncate instead of rounding down in multiplication functions ([21fb32](https://github.com/PaulRBerg/prb-math/commit/21fb32)) (@PaulRBerg)
- Change license to MIT (@PaulRBerg)
- Check if `y` is zero in `gm` ([`5b585c`](https://github.com/PaulRBerg/prb-math/commit/5b585c)) (@PaulRBerg)
- Optimize `avg` by using the SWAR technique ([#89](https://github.com/PaulRBerg/prb-math/pull/89)) (@PaulRBerg)
- Optimize `div` and `mulDivSigned` by wrapping unary operations in unchecked blocks ([`a69b4b`][a69b4b]) (@PaulRBerg)
- Optimize `exp2` by batching bit checks ([#77](https://github.com/PaulRBerg/prb-math/pull/77)) (@k06a)
- Optimize `msb` by using assembly ([#135](https://github.com/PaulRBerg/prb-math/pull/135)) (@t4sk, @PaulRBerg)
- Optimize result assignment in `powu` ([673802](https://github.com/PaulRBerg/prb-math/commit/673802)) (@PaulRBerg)
- Rename `fromInt` to `toSD59x18` and `toInt` to `fromSD59x18` ([`a69b4b`][a69b4b]) (@PaulRBerg)
- Rename `fromUint` to `toUD60x18` and `toUint` to `fromUD60x18` ([`a69b4b`][a69b4b]) (@PaulRBerg)
- Rename `mostSignificantBit` to `msb` ([`a69b4b`][a69b4b]) (@PaulRBerg)
- Rename `mulDivFixedPoint` to `mulDiv18` ([`4c5430`](https://github.com/PaulRBerg/prb-math/commit/4c5430)) (@PaulRBerg)
- Rename `PRBMath.sol` to `Core.sol` ([`1b82ea`][1b82ea]) (@PaulRBerg)
- Rename shared `sqrt` in `prbSqrt` ([`1b82ea`][1b82ea]) (@PaulRBerg)
- Rename shared `exp2` in `prbExp2` ([`1b82ea`][1b82ea]) (@PaulRBerg)
- Revert with inputs instead of computed value custom errors (@PaulRBerg)
- Return base if exponent is one in `pow` ([`977d43`](https://github.com/PaulRBerg/prb-math/commit/977d43)) (@PaulRBerg)
- Format mathematical expressions using LaTeX (@PaulRBerg)
- Improve wording and formatting in comments, NatSpec documentation, and README (@PaulRBerg)
### Added
- Add constants for E and PI ([`422d87`](https://github.com/paulrberg/prb-math/commit/422d87)) (@paulrberg)
- Add simple PRBTest-based typed assertions for testing in Foundry ([`ddb084`](https://github.com/paulrberg/prb-math/commit/ddb084)) (@paulrberg)
- Add user defined value types `SD59x18` and `UD60x18` (@paulrberg)
- Implement conversion and helper functions for the user defined value types (@paulrberg)
- Add constants for E and PI ([`422d87`](https://github.com/PaulRBerg/prb-math/commit/422d87)) (@PaulRBerg)
- Add simple PRBTest-based typed assertions for testing in Foundry ([`ddb084`](https://github.com/PaulRBerg/prb-math/commit/ddb084)) (@PaulRBerg)
- Add user defined value types `SD59x18` and `UD60x18` (@PaulRBerg)
- Implement conversion and helper functions for the user defined value types (@PaulRBerg)
### Removed
- **Breaking:** Delete the `e` and `pi` functions ([422d87](https://github.com/paulrberg/prb-math/commit/422d87)) (@paulrberg)
- **Breaking:** Remove JavaScript SDK and all paraphernalia ([`1b82ea`][1b82ea]) (@paulrberg)
- **Breaking:** Delete the `e` and `pi` functions ([422d87](https://github.com/PaulRBerg/prb-math/commit/422d87)) (@PaulRBerg)
- **Breaking:** Remove JavaScript SDK and all paraphernalia ([`1b82ea`][1b82ea]) (@PaulRBerg)
### Fixed
- Fix incorrect hard-coded value in `sqrt` ([#91](https://github.com/paulrberg/prb-math/pull/91)) (@Amxx, @nonergodic)
- Fix upper boundary specified in `exp` NatSpec comments ([#119](https://github.com/paulrberg/prb-math/discussions/119)) (@paulrberg)
- Fix incorrect hard-coded value in `sqrt` ([#91](https://github.com/PaulRBerg/prb-math/pull/91)) (@Amxx, @nonergodic)
- Fix upper boundary specified in `exp` NatSpec comments ([#119](https://github.com/PaulRBerg/prb-math/discussions/119)) (@PaulRBerg)

@@ -103,5 +125,5 @@ ## [2.5.0] - 2022-03-08

- Change the package name from `prb-math` to `@prb/math` (@paulrberg)
- Update links to repository (@paulrberg)
- Upgrade to `mathjs` v10.4.0 (@paulrberg)
- Change the package name from `prb-math` to `@prb/math` (@PaulRBerg)
- Update links to repository (@PaulRBerg)
- Upgrade to `mathjs` v10.4.0 (@PaulRBerg)

@@ -112,3 +134,3 @@ ## [2.4.3] - 2022-02-02

- Peer dependency version for `mathjs` (@paulrberg)
- Peer dependency version for `mathjs` (@PaulRBerg)

@@ -119,7 +141,7 @@ ## [2.4.2] - 2022-02-02

- Upgrade to `mathjs` v10.1.1 (@paulrberg)
- Upgrade to `mathjs` v10.1.1 (@PaulRBerg)
### Fixed
- Fix typo in comment in `sqrt` ([#67](https://github.com/paulrberg/prb-math/pull/67) (@transmissions11)
- Fix typo in comment in `sqrt` ([#67](https://github.com/PaulRBerg/prb-math/pull/67) (@transmissions11)

@@ -130,7 +152,7 @@ ## [2.4.1] - 2021-10-27

- Upgrade to `@ethersproject/bignumber` v5.5.0 (@paulrberg)
- Upgrade to `@ethersproject/bignumber` v5.5.0 (@PaulRBerg)
### Fixed
- Set peer dependencies (@paulrberg)
- Set peer dependencies (@PaulRBerg)

@@ -141,17 +163,17 @@ ## [2.4.0] - 2021-10-20

- `@ethersproject/bignumber`, `decimal.js`, `evm-bn`, and `mathjs` as normal deps (@paulrberg)
- Ship JavaScript source maps with the npm package (@paulrberg)
- `@ethersproject/bignumber`, `decimal.js`, `evm-bn`, and `mathjs` as normal deps (@PaulRBerg)
- Ship JavaScript source maps with the npm package (@PaulRBerg)
### Changed
- Americanize spellings in NatSpec comments (@paulrberg)
- Move everything from the `prb-math.js` package to `prb-math` (@paulrberg)
- Polish NatSpec comments in `avg` function (@paulrberg)
- Use underscores in number literals (@paulrberg)
- Americanize spellings in NatSpec comments (@PaulRBerg)
- Move everything from the `prb-math.js` package to `prb-math` (@PaulRBerg)
- Polish NatSpec comments in `avg` function (@PaulRBerg)
- Use underscores in number literals (@PaulRBerg)
### Fixed
- Fix bug in the `powu` function of the `PRBMathSD59x18` contract, which caused the result to be positive even if the base was negative (@paulrberg)
- Fix bug in the `powu` function of the `PRBMathSD59x18` contract, which caused the result to be positive even if the base was negative (@PaulRBerg)
- Fix minor bug in the `avg` function of the `PRBMathSD59x18` contract, which rounded down the result instead of up when the intermediary sum was
negative (@paulrberg)
negative (@PaulRBerg)

@@ -162,16 +184,16 @@ ## [2.3.0] - 2021-09-18

- The CHANGELOG file in the npm package bundle (@paulrberg)
- The CHANGELOG file in the npm package bundle (@PaulRBerg)
### Changed
- License from "WTFPL" to "Unlicense" (@paulrberg)
- Polish README (@paulrberg)
- License from "WTFPL" to "Unlicense" (@PaulRBerg)
- Polish README (@PaulRBerg)
### Fixed
- Typos in comments (@paulrberg)
- Typos in comments (@PaulRBerg)
### Removed
- Remove stale "resolutions" field in `package.json` (@paulrberg)
- Remove stale "resolutions" field in `package.json` (@PaulRBerg)

@@ -182,7 +204,7 @@ ## [2.2.0] - 2021-06-27

- Add contract name prefix to custom errors (@paulrberg)
- Add contract name prefix to custom errors (@PaulRBerg)
### Removed
- `@param` tags for custom errors NatSpec (@paulrberg)
- `@param` tags for custom errors NatSpec (@PaulRBerg)

@@ -193,19 +215,19 @@ ## [2.1.0] - 2021-06-27

- Define the upper limit as `MAX_UD60x18 / SCALE` in the `sqrt` function (@paulrberg)
- Define `xValue` var to avoid reading `x.value` multiple times (@paulrberg)
- Move `SCALE > prod1` check at the top of the `mulDivFixedPoint` function (@paulrberg)
- Refer to `add` function operands as summands (@paulrberg)
- Refer to `sub` function operands as minuend and subtrahend (@paulrberg)
- Rename `rUnsigned` var to `rAbs` (@paulrberg)
- Set minimum compiler pragma to `>=0.8.4` (@paulrberg)
- Use `MIN_SD59x18` instead of `type(int256).min` where appropriate (@paulrberg)
- Define the upper limit as `MAX_UD60x18 / SCALE` in the `sqrt` function (@PaulRBerg)
- Define `xValue` var to avoid reading `x.value` multiple times (@PaulRBerg)
- Move `SCALE > prod1` check at the top of the `mulDivFixedPoint` function (@PaulRBerg)
- Refer to `add` function operands as summands (@PaulRBerg)
- Refer to `sub` function operands as minuend and subtrahend (@PaulRBerg)
- Rename `rUnsigned` var to `rAbs` (@PaulRBerg)
- Set minimum compiler pragma to `>=0.8.4` (@PaulRBerg)
- Use `MIN_SD59x18` instead of `type(int256).min` where appropriate (@PaulRBerg)
### Added
- Add Solidity v0.8.4 custom errors (@paulrberg)
- Add Solidity v0.8.4 custom errors (@PaulRBerg)
### Removed
- Remove stale `hardhat/console.sol` import (@paulrberg)
- Remove stale caveat in `sqrt` function NatSpec (@paulrberg)
- Remove stale `hardhat/console.sol` import (@PaulRBerg)
- Remove stale caveat in `sqrt` function NatSpec (@PaulRBerg)

@@ -216,9 +238,9 @@ ## [2.0.1] - 2021-06-16

- Mention the new typed flavors in the README (@paulrberg)
- Mention the new typed flavors in the README (@PaulRBerg)
### Fixed
- Code snippet for the UD60x18Typed consumer in the README (@paulrberg)
- English typos in NatSpec comments ([#40](https://github.com/paulrberg/prb-math/pull/40)) (@ggviana)
- Minor bug in `log10` in `PRBMathUD60x18Typed.sol` which made the result inaccurate when the input was a multiple of 10 (@paulrberg)
- Code snippet for the UD60x18Typed consumer in the README (@PaulRBerg)
- English typos in NatSpec comments ([#40](https://github.com/PaulRBerg/prb-math/pull/40)) (@ggviana)
- Minor bug in `log10` in `PRBMathUD60x18Typed.sol` which made the result inaccurate when the input was a multiple of 10 (@PaulRBerg)

@@ -229,18 +251,18 @@ ## [2.0.0] - 2021-06-14

- Increase the accuracy of `exp2` by using the 192.64-bit format instead of 128.128-bit (@paulrberg)
- Rename `PRBMathCommon.sol` to `PRBMath.sol` (@paulrberg)
- Set named parameter instead of returning result in `pow` functions (@paulrberg)
- Update gas estimates for `exp` and `exp2` (@paulrberg)
- Increase the accuracy of `exp2` by using the 192.64-bit format instead of 128.128-bit (@PaulRBerg)
- Rename `PRBMathCommon.sol` to `PRBMath.sol` (@PaulRBerg)
- Set named parameter instead of returning result in `pow` functions (@PaulRBerg)
- Update gas estimates for `exp` and `exp2` (@PaulRBerg)
### Added
- Add `add` and `sub` functions in the typed libraries (@paulrberg)
- Add types flavors of the library: `PRBMathSD59x18Typed.sol` and `PRBMathUD60x18Typed.sol` (@paulrberg)
- Document gas estimates for `fromInt`, `fromUint`, `pow`, `toInt` and `toUInt` (@paulrberg)
- Structs `PRBMath.SD59x18` and `PRBMath.UD60x18`, simple wrappers to indicate that the variables are fixed-point numbers (@paulrberg)
- Add `add` and `sub` functions in the typed libraries (@PaulRBerg)
- Add types flavors of the library: `PRBMathSD59x18Typed.sol` and `PRBMathUD60x18Typed.sol` (@PaulRBerg)
- Document gas estimates for `fromInt`, `fromUint`, `pow`, `toInt` and `toUInt` (@PaulRBerg)
- Structs `PRBMath.SD59x18` and `PRBMath.UD60x18`, simple wrappers to indicate that the variables are fixed-point numbers (@PaulRBerg)
### Fixed
- Bug in `log10` which made the result incorrect when the input was not a multiple of 10 (@paulrberg)
- Typos in NatSpec comments (@paulrberg)
- Bug in `log10` which made the result incorrect when the input was not a multiple of 10 (@PaulRBerg)
- Typos in NatSpec comments (@PaulRBerg)

@@ -253,16 +275,16 @@ ## [1.1.0] - 2021-05-07

- Rename the previous `pow` function to `powu` (@paulrberg)
- Speed up `exp2` by simplifying the integer part calculations (@paulrberg)
- Use the fixed-point format in NatSpec comments (@paulrberg)
- Rename the previous `pow` function to `powu` (@PaulRBerg)
- Speed up `exp2` by simplifying the integer part calculations (@PaulRBerg)
- Use the fixed-point format in NatSpec comments (@PaulRBerg)
### Added
- Add new convertor functions `fromInt` and `toInt` in `PRBMathSD59x18.sol` (@paulrberg)
- Add new convertor functions `fromUint` and `toUint` in `PRBMathUD60x18.sol` (@paulrberg)
- Add new function `mulDivSigned` in `PRBMathCommon.sol` (@paulrberg)
- Add new function `pow` in `PRBMathSD59x18.sol` and `PRBMathUD60x18.sol` (@paulrberg)
- Add new convertor functions `fromInt` and `toInt` in `PRBMathSD59x18.sol` (@PaulRBerg)
- Add new convertor functions `fromUint` and `toUint` in `PRBMathUD60x18.sol` (@PaulRBerg)
- Add new function `mulDivSigned` in `PRBMathCommon.sol` (@PaulRBerg)
- Add new function `pow` in `PRBMathSD59x18.sol` and `PRBMathUD60x18.sol` (@PaulRBerg)
### Fixed
- Fix minor typos in NatSpec comments (@paulrberg)
- Fix minor typos in NatSpec comments (@PaulRBerg)

@@ -273,8 +295,8 @@ ## [1.0.5] - 2021-04-24

- Speed up the `exp2` function in PRBMathCommon.sol by simplifying the integer part calculation (@paulrberg))
- Use `SCALE` instead of the 1e18 literal in `PRBMathCommon.sol` (@paulrberg)
- Speed up the `exp2` function in PRBMathCommon.sol by simplifying the integer part calculation (@PaulRBerg))
- Use `SCALE` instead of the 1e18 literal in `PRBMathCommon.sol` (@PaulRBerg)
### Added
- Add link to StackExchange answer in `exp2` NatSpec comments (@paulrberg)
- Add link to StackExchange answer in `exp2` NatSpec comments (@PaulRBerg)

@@ -285,3 +307,3 @@ ## [1.0.4] - 2021-04-20

- Optimize the `pow` function in PRBMathUD60x18.sol by calling `mulDivFixedPoint` directly (@paulrberg)
- Optimize the `pow` function in PRBMathUD60x18.sol by calling `mulDivFixedPoint` directly (@PaulRBerg)

@@ -292,8 +314,8 @@ ## [1.0.3] - 2021-04-20

- Fix typos in NatSpec comments (@paulrberg)
- Fix typo in example in README (@paulrberg)
- Fix typos in NatSpec comments (@PaulRBerg)
- Fix typo in example in README (@PaulRBerg)
### Removed
- Remove `SCALE_LPOTD` and `SCALE_INVERSE` constants in PRBMathSD59x18.sol (@paulrberg)
- Remove `SCALE_LPOTD` and `SCALE_INVERSE` constants in PRBMathSD59x18.sol (@PaulRBerg)

@@ -304,3 +326,3 @@ ## [1.0.2] - 2021-04-19

- Remove stale `SCALE_LPOTD` and `SCALE_INVERSE` constants in PRBMathUD60x18.sol (@paulrberg)
- Remove stale `SCALE_LPOTD` and `SCALE_INVERSE` constants in PRBMathUD60x18.sol (@PaulRBerg)

@@ -311,3 +333,3 @@ ## [1.0.1] - 2021-04-19

- Change in the README (@paulrberg)
- Change in the README (@PaulRBerg)

@@ -318,2 +340,2 @@ ## [1.0.0] - 2021-04-19

- First release of the library (@paulrberg)
- First release of the library (@PaulRBerg)
MIT License
Copyright (c) 2022 Paul Razvan Berg
Copyright (c) 2023 Paul Razvan Berg

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to

{
"name": "@prb/math",
"description": "Solidity library for advanced fixed-point math",
"version": "3.2.0",
"version": "3.3.0",
"author": {
"name": "Paul Razvan Berg",
"url": "https://github.com/paulrberg"
"url": "https://github.com/PaulRBerg"
},
"bugs": {
"url": "https://github.com/paulrberg/prb-math/issues"
"url": "https://github.com/PaulRBerg/prb-math/issues"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"commitizen": "^4.2.5",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"husky": "^8.0.2",
"lint-staged": "^13.0.4",
"husky": "^8.0.3",
"lint-staged": "^13.1.0",
"pinst": "^3.0.0",
"prettier": "^2.8.0",
"prettier-plugin-solidity": "^1.0.0",
"rimraf": "^3.0.2",
"solhint": "^3.3.7",
"prettier": "^2.8.3",
"prettier-plugin-solidity": "^1.1.2",
"rimraf": "^4.1.2",
"solhint": "^3.3.8",
"solhint-plugin-prettier": "^0.0.5"

@@ -30,14 +30,15 @@ },

],
"homepage": "https://github.com/paulrberg/prb-math#readme",
"homepage": "https://github.com/PaulRBerg/prb-math#readme",
"keywords": [
"arithmetic",
"blockchain",
"ethereum",
"fixed-point-math",
"library",
"math",
"smart-contracts",
"solidity",
"typescript"
"solidity"
],
"license": "MIT",
"packageManager": "yarn@3.3.0",
"packageManager": "yarn@3.4.1",
"publishConfig": {

@@ -48,11 +49,8 @@ "access": "public"

"type": "git",
"url": "https://github.com/paulrberg/prb-math"
"url": "https://github.com/PaulRBerg/prb-math"
},
"resolutions": {
"solhint/@solidity-parser/parser": "^0.14.5"
},
"scripts": {
"build": "forge build",
"clean": "rimraf cache out",
"lint": "yarn lint:sol && yarn prettier:check",
"lint:sol": "solhint \"{src,test}/**/*.sol\"",
"lint": "yarn prettier:check && yarn solhint \"{src,test}/**/*.sol\"",
"_postinstall": "husky install",

@@ -59,0 +57,0 @@ "postpublish": "pinst --enable",

# PRBMath [![GitHub Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![Styled with Prettier][prettier-badge]][prettier] [![License: MIT][license-badge]][license]
[gha]: https://github.com/paulrberg/prb-math/actions
[gha-badge]: https://github.com/paulrberg/prb-math/actions/workflows/ci.yml/badge.svg
[gha]: https://github.com/PaulRBerg/prb-math/actions
[gha-badge]: https://github.com/PaulRBerg/prb-math/actions/workflows/ci.yml/badge.svg
[foundry]: https://getfoundry.sh/

@@ -18,3 +18,3 @@ [foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg

- Offers advanced math functions like logarithms, exponentials, powers and square roots
- Provides type safety via user defined value types
- Provides type safety via user-defined value types
- Gas efficient, but still user-friendly

@@ -40,3 +40,3 @@ - Ergonomic developer experience thanks to using free functions instead of libraries

```sh
forge install --no-commit paulrberg/prb-math@v3
forge install --no-commit PaulRBerg/prb-math@v3
```

@@ -60,3 +60,3 @@

PRBMath comes in two flavors:
There are two user-defined value types:

@@ -66,7 +66,13 @@ 1. SD59x18 (signed)

If you don't need negative numbers, there's no point in using the signed flavor. The unsigned flavor is more gas efficient.
If you don't know what a user-defined value type is, check out [this blog post](https://blog.soliditylang.org/2021/09/27/user-defined-value-types/).
If you don't need negative numbers, there's no point in using the signed flavor `SD59x18`. The unsigned flavor `UD60x18` is more gas efficient.
Note 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
of free functions.
### Importing
It is recommended that you import PRBMath in the global scope, because you will often need multiple symbols:
It is recommended that you import PRBMath using specific symbols. Importing full files can result in Solidity complaining about duplicate definitions
and static analyzers like Slither erroring, especially as repos grow and have more dependencies with overlapping names.

@@ -76,5 +82,13 @@ ```solidity

import "@prb/math/SD59x18.sol";
import "@prb/math/UD60x18.sol";
import { SD59x18 } from "@prb/math/SD59x18.sol";
import { UD60x18 } from "@prb/math/UD60x18.sol";
```
Any function that is not available in the types directly has to be imported explicitly. Here's an example for the `sd` and the `ud` functions:
```solidity
pragma solidity >=0.8.13;
import { SD59x18, sd } from "@prb/math/SD59x18.sol";
import { UD60x18, ud } from "@prb/math/UD60x18.sol";
```

@@ -90,3 +104,3 @@

import "@prb/math/SD59x18.sol";
import { SD59x18, sd } from "@prb/math/SD59x18.sol";

@@ -104,6 +118,5 @@ contract SignedConsumer {

function signedLog2(SD59x18 x) external pure returns (SD59x18 result) {
result = log2(x);
result = x.log2();
}
}
```

@@ -117,3 +130,3 @@

import "@prb/math/UD60x18.sol";
import { UD60x18, ud } from "@prb/math/UD60x18.sol";

@@ -131,6 +144,5 @@ contract UnsignedConsumer {

function unsignedLog2(UD60x18 x) external pure returns (UD60x18 result) {
result = log2(x);
result = x.log2();
}
}
```

@@ -165,24 +177,53 @@

### Adjacent Value Types
PRBMath provides adjacent value types that serve as abstractions over other vanilla types such as `int64`. The types currently available are:
| Value Type | Underlying Type |
| ---------- | --------------- |
| `SD1x18` | int64 |
| `UD2x18` | uint64 |
These are useful if you want to save gas by using a lower bit width integer, e.g. in a struct.
Note 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
the core types `SD59x18` and `UD60x18`.
### Casting Functions
All PRBMath types have casting functions to and from all other types, including a few basic types like `uint128` and `uint40`.
| Name | Description |
| ------------- | ------------------------- |
| `intoSD1x18` | Casts a number to SD1x18 |
| `intoSD59x18` | Casts a number to SD59x18 |
| `intoUD2x18` | Casts a number to UD2x18 |
| `intoUD60x18` | Casts a number to UD60x18 |
| `intoUint256` | Casts a number to uint256 |
| `intoUint128` | Casts a number to uint128 |
| `intoUint40` | Casts a number to uint40 |
| `sd1x18` | Alias for `SD1x18.wrap` |
| `sd59x18` | Alias for `SD59x18.wrap` |
| `ud2x18` | Alias for `UD2x18.wrap` |
| `ud60x18` | Alias for `UD60x18.wrap` |
### Conversion Functions
| Name | Description |
| ------------- | --------------------------------------------------------------------- |
| `fromSD59x18` | Converts an SD59x18 number to a simple integer by dividing it by 1e18 |
| `fromUD60x18` | Converts an UD60x18 number to a simple integer by dividing it by 1e18 |
| `sd` | Alias for `wrap`, wraps a simple integer into SD59x18 |
| `sd59x18` | Alias for `wrap`, wraps a simple integer into SD59x18 |
| `toSD59x18` | Converts a simple integer to SD59x18 by multiplying it by 1e18 |
| `toUD60x18` | Converts a simple integer to UD60x18 by multiplying it by 1e18 |
| `ud` | Alias for `wrap`, wraps a simple integer into UD60x18 |
| `ud60x18` | Alias for `wrap`, wraps a simple integer into UD60x18 |
| `unwrap` | Unwrap an SD59x18 or UD60x18 number into a simple integer |
| `wrap` | Wraps a simple integer into either SD59x18 or UD60x18 |
The difference between "conversion" and "casting" is that conversion functions multiply or divide the inputs, whereas casting functions simply cast
them.
| Name | Description |
| ------------------ | --------------------------------------------------------------------- |
| `convert(SD59x18)` | Converts an SD59x18 number to a simple integer by dividing it by 1e18 |
| `convert(UD60x18)` | Converts an UD60x18 number to a simple integer by dividing it by 1e18 |
| `convert(int256)` | Converts a simple integer to SD59x18 by multiplying it by 1e18 |
| `convert(uint256)` | Converts a simple integer to UD60x18 type by multiplying it by 1e18 |
### Helper Functions
In addition to the mathematical and the conversion functions, PRBMath provides many other helpers for the user-defined value types, such as
`add`,`eq`, and `rshift`. These functions are not part of the core API and are frequently updated, so I invite you to take a look at the source code
In addition to the mathematical, casting, and conversion functions, PRBMath provides many other helpers for the user-defined value types, such as
`add`, `eq`, and `rshift`. These functions are not part of the core API and are frequently updated, so I invite you to take a look at the source code
to see the full list.
The goal with these helpers is not have to always unwrap and re-wrap variables to perform such basic operations as addition and equality checks.
The goal with these helpers is to not have to always unwrap and re-wrap variables to perform such basic operations as addition and equality checks.
However, you should note that using these functions instead of the vanilla operators (e.g. `+`, `==`, and `>>`) will result in a higher gas cost.

@@ -194,3 +235,3 @@

import "@prb/math/UD60x18.sol";
import { UD60x18, ud } "@prb/math/UD60x18.sol";

@@ -202,3 +243,3 @@ function addRshiftEq() pure returns (bool result) {

y = y.rshift(2);
result = eq(x, y);
result = x.eq(y);
}

@@ -208,19 +249,5 @@

### Adjacent Value Types
PRBMath provides adjacent value types that serve as abstractions over other vanilla types such as `int64`. The types currently available are:
| Value Type | Underlying Type |
| ---------- | --------------- |
| `SD1x18` | int64 |
| `UD2x18` | uint64 |
These are useful if you want to save gas by using a lower bit width integer, e.g. in a struct.
Note that these types don't have any mathematical functionality. For that, you will have to unwrap them into a simple integer and then to the core
types `SD59x18` and `UD60x18`.
### Assertions
PRBMath is shipped with typed assertions that you can use for writing tests with [PRBTest](https://github.com/paulrberg/prb-test), which is based on
PRBMath is shipped with typed assertions that you can use for writing tests with [PRBTest](https://github.com/PaulRBerg/prb-test), which is based on
Foundry. This is useful if, for example, you would like to assert that two SD59x18 or UD60x18 numbers are equal.

@@ -231,3 +258,3 @@

import "@prb/math/UD60x18.sol";
import { UD60x18, ud } from "@prb/math/UD60x18.sol";
import { Assertions as PRBMathAssertions } from "@prb/math/test/Assertions.sol";

@@ -244,3 +271,2 @@ import { PRBTest } from "@prb/math/test/PRBTest.sol";

}
```

@@ -257,8 +283,8 @@

**Note**: I did not find a good way to automatically generate gas reports for PRBMath. See the
[#134](https://github.com/paulrberg/prb-math/discussions/134) discussion for more details about this issue.
[#134](https://github.com/PaulRBerg/prb-math/discussions/134) discussion for more details about this issue.
### PRBMath
Gas estimations based on the [v2.0.1](https://github.com/paulrberg/prb-math/releases/tag/v2.0.1) and the
[v3.0.0](https://github.com/paulrberg/prb-math/releases/tag/v3.0.0) releases.
Gas estimations based on the [v2.0.1](https://github.com/PaulRBerg/prb-math/releases/tag/v2.0.1) and the
[v3.0.0](https://github.com/PaulRBerg/prb-math/releases/tag/v3.0.0) releases.

@@ -287,3 +313,3 @@ | SD59x18 | Min | Max | Avg | | UD60x18 | Min | Max | Avg |

Gas estimations based on the v3.0 release of ABDKMath. See my [abdk-gas-estimations](https://github.com/paulrberg/abdk-gas-estimations) repo.
Gas estimations based on the v3.0 release of ABDKMath. See my [abdk-gas-estimations](https://github.com/PaulRBerg/abdk-gas-estimations) repo.

@@ -307,4 +333,4 @@ | Method | Min | Max | Avg |

Feel free to dive in! [Open](https://github.com/paulrberb/prb-math/issues/new) an issue,
[start](https://github.com/paulrberb/prb-math/discussions/new) a discussion or submit a PR.
Feel free to dive in! [Open](https://github.com/PaulRBerg/prb-math/issues/new) an issue,
[start](https://github.com/PaulRBerg/prb-math/discussions/new) a discussion or submit a PR.

@@ -327,3 +353,3 @@ ### Pre Requisites

```sh
$ git clone --recurse-submodules -j8 git@github.com:paulrberg/prb-math.git
$ git clone --recurse-submodules -j8 git@github.com:PaulRBerg/prb-math.git
```

@@ -358,5 +384,5 @@

If you discover any bugs or security issues, please report them via [Telegram](https://t.me/paulrberg).
If you discover any bugs or security issues, please report them via [Telegram](https://t.me/PaulRBerg).
## Acknowledgements
## Acknowledgments

@@ -371,2 +397,2 @@ - Mikhail Vladimirov for the insights he shared in his [Math in Solidity](https://medium.com/coinmonks/math-in-solidity-part-1-numbers-384c8377f26d)

[MIT](./LICENSE.md)
[MIT](./LICENSE.md) © Paul Razvan Berg

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc