 # Will there ever be exponentiation in Move?

Quick and simple question. Is exponentiation operator (hence bytecode/op) ignored by design? And what is the reason for it? And is there any hack (except loops) to calculate powers of 10 with any given `u8` argument?

Good question. We don’t have any code using exponentiation, but it’s something you would want as soon as you start writing crypto or other mathematical code on-chain.

We discussed this with the team a bit and although we’re not sure about an opcode yet (EVM has one but Java/CLR/Webassembly bytecode do not), a `Math` module with exponentiation and other common functions would make sense. We can start off with pure Move implementations of these functions and later replace them with efficient native functions and (eventually) bytecodes if needed. Will put this on the roadmap (or happy to accept contributions if you already have useful functions!).

1 Like

Wow. I was going to start working on Math today! I will finish it eventually and happy to contribute!

Though in crypto the main problem is integer calculations with different meant decimals points. That’s why I need pow() method - to convert different scales to one.

e.g.

``````let eth = 1000000000000000000; // 18 decimals
let btc = 100000000; // 8 decimals
let eth_btc_rate = 40000000; // 8 decimals

let result_btc = eth * eth_btc_rate; // error is 10^10 times
``````

So maybe I would need something like: `convert(eth, 18, 8)` or a different approach. I’m open to suggestions and will soon present you my Math module.

1 Like

That’s why I need pow() method - to convert different scales to one.

Ah, for this use-case the `FixedPoint32` module might be useful? CC @bobwilson and @tzakian

For fixed-point binary representations (like in FixedPoint32), you can use bit-wise shift operations instead of exponentiation, but if you need decimal conversions like that, exponentiation will be important if the exponents are not known in advance. I.E., I think you can write that conversion function specifically for decimal exponents of 18 and 8 using multiplication/division, but if you want a general conversion for arbitrary exponents, that’s when you want the exponentiation.

2 Likes

Yeah. 18 and 8 are just one of them. There can be any value from 0 to 18, so more general approach is what I need.

Also. Regarding FixedPoint32 I am operating u128 values, so larger scale with u256 is required. And u256 currently requires native functions and its structs so it won’t be that easy to implement.

Thanks for response! I’ll post Math module soon!