Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FullMath.mulDivQ128 and optimize Position.update #601

Closed
wants to merge 6 commits into from

Conversation

shuhuiluo
Copy link
Contributor

Related Issue

Which issue does this pull request resolve?

Description of changes

A new function named mulDivQ128 has been added to FullMath. This function calculates x * y / 2^128 with full precision. The calls to mulDiv in Position.sol were updated to use this new function. The changes also resulted in a decrease in gas in multiple snapshots. Tests were added to validate the functionality of mulDivQ128.

Also optimized the overflow check within the mulDivRoundingUp function of FullMath library. This is achieved by combining two steps: the increment of the result and the overflow check, into a single step using the ++ operator.

A new function named `mulDivQ128` has been added to `FullMath`. This function calculates x * y / 2^128 with full precision. The calls to `mulDiv` in `Position.sol` were updated to use this new function. The changes also resulted in a decrease in gas in multiple snapshots. Tests were added to validate the functionality of `mulDivQ128`.
This commit optimizes the overflow check within the `mulDivRoundingUp` function of FullMath library. This is achieved by combining two steps: the increment of the `result` and the overflow check, into a single step using the `++` operator. This simplifies the code, improves its readability and brings down the gas usage slightly, as reflected in updated snapshot files.
@shuhuiluo shuhuiluo changed the title Add FullMath.mulDivQ128 and optimize mulDivRoundingUp Add FullMath.mulDivQ128 and optimize Position.update May 23, 2024
@hensha256 hensha256 closed this Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants