-
Hello! We're looking to implement an EMA in Solidity, which requires us to compute
where:
The However, it is limited by 18 decimal precision given that We are trying to modify the It appears that we can change the number of decimals by modifying the constants here, the constants being
Appreciate any help in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @publiuss, I'm glad that you find my implementation of
I'm sorry for the vague answers. I designed PRBMath with 18 decimals in mind and I never really thought deeply about other decimal systems. A related conversation that might be a good read for you is this post on the OpenZeppelin forum: Designing Fixed Point Math in OpenZeppelin Contracts. |
Beta Was this translation helpful? Give feedback.
Hello @publiuss, I'm glad that you find my implementation of
powu
function useful.SCALE_LPOTD
andSCALE_INVERSE
.SCALE_LPOTD
is 262144 because that is the largest power of two that divides 1e18