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 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
love the library! wondering what the recommendation would be when dealing with
uint
values 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 thanuint256
itself?thought was to do a normal
_mulDiv
and 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)
Beta Was this translation helpful? Give feedback.
All reactions