Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour of Pow changed in v1.4 #380

Open
EVODelavega opened this issue Jul 23, 2024 · 0 comments
Open

Behaviour of Pow changed in v1.4 #380

EVODelavega opened this issue Jul 23, 2024 · 0 comments

Comments

@EVODelavega
Copy link

As part of v1.4.0, the PowPrecisionNegativeExponent was added, which limits the default precision of Pow() when using negative exponents to 16. When using this package to express amounts of crypto assets, 18 decimal places is extremely common. Storing balances/transfer amounts in the smallest possible decimal (e.g. in case of ETH, storing the amounts in wei) is standard practice. Converting these amounts to and from a more human-readable format (or the corresponding amount in ETH), I rely on a fair amount of code that looks somewhat like this:

    asset := app.GetAsset(assetID)
    // 10e-18
    factor := decimal.DecimalFromFloat(10).Pow(decimal.NewFromInt(-asset.Decimals))
    inAsset := someAmount.Mul(factor)

This worked fine before updating the dependency version, where there was no cap on the negative exponent when calling Pow. For my use-case, setting this value to at least a sensible default makes more sense, but truthfully, I believe a negative exponent ought not to be capped. Using 10^-N is an expression of precision in and of itself.

As part of the linked PR, I've also increased the default division precision to 18 for the same reason as above (crypto assets having 18 decimal places). I've kept it as a separate commit, which I can revert if needed.

PR: #379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant