1

https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol

This above is the link of FixedPointMathLib.sol. There are these functions .Can somebdoy explain what the function does. foe example MulDivDown

1 Answer 1

1

This library is used to perform mathematical equations on numbers in 18 decimal precision (WAD). This is useful because most of the ERC20 tokens are encoded in 18 decimal precision.

Example: You would like to divide a by b. a = 2 * 10^18 aka 10 in 18 decimal precision b = a

Now normally a / b would return 1, but in 18 decimal precision this would mean 0.00...01. To fix this we have to multiply the result with 10^18, which is exactly what the library does for us.

There are also different methods depending on how you want to round the result. Solidity always rounds the result down, so to do the opposite, the function in FixedPointMath adds the difference.

1
  • Why is the 0.00...01 happening? Does it have to do with the way numbers are stored and calculated in Solidity? I'm curious
    – Ishan
    Sep 24, 2023 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.