Bonsaiswap Docs
  • 🌿Bonsaiswap Intro
  • Get Started
    • Create a Wallet
    • Get ERC20 Tokens
  • Roadmap
  • Products
    • 🔄Exchange
      • Swapping Tokens
      • Providing Liquidity
    • 🔮Coming Soon!
  • Tokenomics
    • 🎍AKADAMA
  • Developers
    • 🛠️Technical Reference
      • Core
        • BonsaiswapV3Factory
        • BonsaiswapV3Pool
        • BonsaiswapV3PoolDeployer
        • Interfaces
          • IERC20Minimal
          • IBonsaiswapV3Factory
          • IBonsaiswapV3Pool
          • IBonsaiswapV3PoolDeployer
          • callback
            • IBonsaiswapV3FlashCallback
            • IBonsaiswapV3MintCallback
            • IBonsaiswapV3SwapCallback
          • Pool
            • IBonsaiswapV3PoolActions
            • IBonsaiswapV3PoolDerivedState
            • IBonsaiswapV3PoolEvents
            • IBonsaiswapV3PoolImmutables
            • IBonsaiswapV3PoolOwnerActions
            • IBonsaiswapV3PoolState
        • Libraries
          • BitMath
          • FixedPoint128
          • FixedPoint96
          • FullMath
          • LiquidityMath
          • LowGasSafeMath
          • Oracle
          • Position
          • SafeCast
          • SecondsOutside
          • SqrtPriceMath
          • SwapMath
          • Tick
          • TickBitmap
          • TickMath
          • TransferHelper
          • UnsafeMath
      • Periphery
        • Base
          • BlockTimestamp
          • ERC721Permit
          • LiquidityManagement
          • Multicall
          • PeripheryImmutableState
          • PeripheryPayments
          • PeripheryPaymentsWithFee
          • PoolInitializer
          • SelfPermit
        • Interfaces
          • IERC20Metadata
          • IERC721Permit
          • IMulticall
          • INonfungiblePositionManager
          • INonfungibleTokenPositionDescriptor
          • IPeripheryImmutableState
          • IPeripheryPayments
          • IPeripheryPaymentsWithFee
          • IPoolInitializer
          • IQuoter
          • IQuoterV2
          • ISelfPermit
          • ISwapRouter
          • ITickLens
          • external
            • IERC1271
            • IERC20PermitAllowed
            • IWETH9
        • Lens
          • Quoter
          • QuoterV2
          • TickLens
        • Libraries
          • Base64
          • BytesLib
          • CallbackValidation
          • ChainId
          • HexStrings
          • LiquidityAmounts
          • NFTDescriptor
          • NFTSVG
          • OracleLibrary
          • Path
          • PoolAddress
          • PoolTicksCounter
          • PositionKey
          • TokenRatioSortOrder
          • TransferHelper
          • WeightedOracleLibrary
        • NonfungiblePositionManager
        • NonfungibleTokenPositionDescriptor
        • SwapRouter
        • V3Migrator
      • Deployment Addresses
      • Error Codes
Powered by GitBook
On this page
  1. Developers
  2. Technical Reference
  3. Core
  4. Libraries

FullMath

PreviousFixedPoint96NextLiquidityMath

Last updated 2 years ago

Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision

Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits

Functions

mulDiv

  function mulDiv(
    uint256 a,
    uint256 b,
    uint256 denominator
  ) internal pure returns (uint256 result)

Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0

Credit to Remco Bloemen under MIT license

Parameters:

Name
Type
Description

a

uint256

The multiplicand

b

uint256

The multiplier

denominator

uint256

The divisor

Return Values:

Name
Type
Description

result

uint256

The 256-bit result

mulDivRoundingUp

  function mulDivRoundingUp(
    uint256 a,
    uint256 b,
    uint256 denominator
  ) internal pure returns (uint256 result)

Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0

Name
Type
Description

a

uint256

The multiplicand

b

uint256

The multiplier

denominator

uint256

The divisor

Name
Type
Description

result

uint256

The 256-bit result

Parameters:

Return Values:

🛠️
​
​
https://xn--2-umb.com/21/muldiv
​
​
​
​
​