Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
it4rb committed Jan 24, 2024
1 parent b23e560 commit ba93920
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions utils/full_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func MulDivRoundingUpV2(a, b, denominator, result *uint256.Int) error {

// result=floor(a×b÷denominator), remainder=a×b%denominator
// (pass remainder=nil if not required)
// (the main usage for `remainder` is to be used in `MulDivRoundingUpV2` to determine if we need to round up, so it won't have to call MulMod again)
func MulDivV2(a, b, denominator, result, remainder *uint256.Int) error {
// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
// 512-bit multiply [prod1 prod0] = a * b
Expand Down Expand Up @@ -76,6 +77,7 @@ func MulDivV2(a, b, denominator, result, remainder *uint256.Int) error {
}

if remainder != nil {
// if the caller request then calculate remainder
remainder.MulMod(a, b, &denominatorTmp)
}
result.Div(&prod0, &denominatorTmp)
Expand All @@ -95,6 +97,7 @@ func MulDivV2(a, b, denominator, result, remainder *uint256.Int) error {
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
if remainder == nil {
// the caller doesn't request but we need it so use a temporary variable here
var remainderTmp Uint256
remainder = &remainderTmp
}
Expand Down

0 comments on commit ba93920

Please sign in to comment.