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

Add support to Math.Pow #834

Open
lock9 opened this issue Dec 14, 2023 · 5 comments
Open

Add support to Math.Pow #834

lock9 opened this issue Dec 14, 2023 · 5 comments

Comments

@lock9
Copy link
Contributor

lock9 commented Dec 14, 2023

Problem:
The Decimals property "can't" be used inside smart contracts to deal with the supply.
Example: It's not possible to convert 100_000_000 to 100_000_000.00000000.

Solution:
Add support to Math.Pow (or equivalent).
Python Example:

@public(name="totalSupply", safe=True)
def total_supply() -> int:
    return 100000000 * 10 ** decimals() # 100,000,000.00000000

Note: I'm not sure if there is another solution for this.

Question: How do people calculate the total supply without using the decimals property? (inside the smart contract).

@Jim8y
Copy link
Contributor

Jim8y commented Dec 15, 2023

BigInteger.Pow

@lock9
Copy link
Contributor Author

lock9 commented Dec 15, 2023

Would it be hard to add Math.Pow and make it work like BigInteger.Pow?
Identical behavior, just so it's easier to use

@cschuchardt88
Copy link
Member

Can't you use BigInteger in python? Would be like this:

BigInteger.Pow(100_000_000, 8); // (value, exponent)

@Jim8y
Copy link
Contributor

Jim8y commented Dec 15, 2023

Would it be hard to add Math.Pow and make it work like BigInteger.Pow?

Identical behavior, just so it's easier to use

Well, not hard at all, just a few lines of code. I am working to make the method support more complete, but will take time to get merged.

@lock9
Copy link
Contributor Author

lock9 commented Dec 15, 2023

Sure, no rush. Thank you for looking into it

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

Successfully merging a pull request may close this issue.

3 participants