neo-devpack-dotnet icon indicating copy to clipboard operation
neo-devpack-dotnet copied to clipboard

Add support to Math.Pow

Open lock9 opened this issue 2 years ago • 5 comments

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).

lock9 avatar Dec 14 '23 22:12 lock9

BigInteger.Pow

Jim8y avatar Dec 15 '23 01:12 Jim8y

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

lock9 avatar Dec 15 '23 03:12 lock9

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

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

cschuchardt88 avatar Dec 15 '23 03:12 cschuchardt88

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.

Jim8y avatar Dec 15 '23 03:12 Jim8y

Sure, no rush. Thank you for looking into it

lock9 avatar Dec 15 '23 12:12 lock9