MathLib library provides gas-optimized mathematical utility functions used throughout the Morpho Vault V2 system.
Functions
mulDivDown
(x * y) / d rounded down.
The first multiplicand
The second multiplicand
The divisor
(x * y) / d rounded down
mulDivUp
(x * y) / d rounded up.
The first multiplicand
The second multiplicand
The divisor
(x * y) / d rounded up
zeroFloorSub
max(0, x - y), preventing underflow by returning 0 if y > x.
The minuend
The subtrahend
x - y if x > y, otherwise 0
toUint128
uint256 to uint128, reverting if the input number is too large.
The value to cast
uint128
Reverts: ErrorsLib.CastOverflow() if x > type(uint128).max
toUint256
int256 to uint256, reverting if the input number is negative.
The value to cast
uint256
Reverts: ErrorsLib.CastOverflow() if x < 0
min
The first value
The second value
x and y