Replies: 4 comments 2 replies
-
I did some experimentation with the open-zeppelin maths library too:
This prints:
|
Beta Was this translation helpful? Give feedback.
-
Hey @JasoonS, thanks very much for opening a discussion about this! Feedback is always welcome, since it helps me improve the usefulness of the library. I will be upfront, I don't have any plans for adding support different types of rounding modes in V3 (the next version of PRBMath, which I will ship soon-ish). As explained in the NatSpec of the However, if I keep receiving requests for rounding modes, I may consider implementing it in PRBMath V4. I'm curious. May I ask you why do you "require" that multiplication rounds down, always? |
Beta Was this translation helpful? Give feedback.
-
Thanks @PaulRBerg .
I was looking at using this for https://float.capital v2. We do asynchronous maths on a per user basis and on a batched basis with multiplication division. If the sum of all the per user operations is greater than the operation on the whole batch we are at risk of overflow. More specifically, we calculate how much erc20 token to mint for all the users in the batch with 1 multiplication on the batch. But then each user individually claims those tokens in their own time later. If the sum of all the user claims is greater than the batch the contract breaks. Rounding down makes this impossible (although some dust tokens will accumulate over time). Really awesome stuff on the library - very useful tool for the box 🙌 Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi @JasoonS, I have recently released PRBMath v3.0.0, and I am happy to let you know that I listened to your feedback here and changed the behavior of the Does this address your need? |
Beta Was this translation helpful? Give feedback.
-
In our code we require that multiplication rounds down always.
Is there a way to use this library with that in mind? Would there be plans to do that?
Thanks
As an example in the following code:
Prints
The actual result is 649.644582538276888395838879597179076803 (with 18 decimal precision) so it is shown it is rounding up (not taking the floor), but I see the docs for
mulDivFixedPoint
say:Beta Was this translation helpful? Give feedback.
All reactions