Arbitrary number of decimals. #64
Replies: 2 comments 1 reply
-
Hey! Unfortunately, while possible, this would be non-trivial to implement. It's just not some constants that make the library to work with 18 decimals - the library is much more sophisticated than that. For example, the exp2 function uses the You may want to read this thread on the OpenZeppelin forum: Designing Fixed Point Math in OpenZeppelin Contracts. The consensus there was clear - fixed-point number of decimals is superior (gives better security and guarantees) and it is easier to maintain. What do you need arbitrary number of decimals for? |
Beta Was this translation helpful? Give feedback.
-
@PaulRBerg I am struggling to figure out a nice clean way to do math when dealing with tokens of different decimal places. So far I have resorted to padding everything to 18 decimals, and it works well, its just verbose and there is the potential for overflow causing revert with very large numbers (unlikely but in theory possible). Modified a section of your code to get that part working. I pass in (18 - token.decimals() to pad to 18)
|
Beta Was this translation helpful? Give feedback.
-
Is it possible to set up things such that this library could be used as 61x17? or 65x13?
From briefly reading through the code, adjusting the SCALE and HALF_SCALE values should be able to accomplish this without throwing the math out of whack?
Is this something that has been explored? @PaulRBerg?
Also haven't forgetting about #51, it's under way.
Cheers,
bera dev
Beta Was this translation helpful? Give feedback.
All reactions