Skip to content

Commit

Permalink
Simplify twos calculation in mulDiv
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Jul 31, 2023
1 parent 65033cc commit f5e8beb
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions contracts/utils/math/Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ library Math {
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.

// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
Expand Down

0 comments on commit f5e8beb

Please sign in to comment.