Replies: 1 comment
|
The short answer is that there are no best practices for your use case. The user is expected to use the same bit-width as the library types. If you're using custom types and operations that may result in a value greater than the underlying type allows, you would have to write your own subroutines and check for overflow after every math operation. Side note: what version of PRBMath are you using? In V4, there are user-defined value types. You could consider writing your bespoke value types - as I've done with |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
love the library! wondering what the recommendation would be when dealing with
uintvalues that aren'tuint256(maybe due to struct packing)? Specifically is there a pattern/best practice around doing fixed-math with values that need to fit in something that is smaller thanuint256itself?Struct A { uint80 price; uint88 quantity; uint256 total; } // this works since both values are casted to uint256 already. uint256 total = price.mul(quantity); Struct B { uint80 price; uint88 quantity; uint88 total; } // what about wanting to use the library when the result needs to fit in a smaller uint? uint88 total = ?thought was to do a normal
_mulDivand save the result as a uint256, and then check for overflow, then return the result? only tedious thing is that due to typing each different uint needs it's own checksor is that an invalid way of going about this? (and this is assuming 18 decimals still, just smaller max values)
All reactions