Apparently Axe changed the ^ to take a module of something, is it still possible to get a power of a number or is it completely removed?


here is the code that I have now

Code:
2->G
15*(1.15^G)->H
There's no builtin way by default, as far as I can tell. You may want to look at exponentiation by squaring if you want to implement it yourself as a function.
ThatGuyWithTheStuff wrote:
Apparently Axe changed the ^ to take a module of something, is it still possible to get a power of a number or is it completely removed?


here is the code that I have now

Code:
2->G
15*(1.15^G)->H

For some reason this reminds me of Cookie Clicker's price-calculating function...but whatever.

I would assume that, for A to the power of B, where B is an integer power >1, you could simply do something like this (this is pseudocode; thinking about the most optimized way to code this in Axe will hurt my brain):

Code:

A -> C
Repeat B-1 times
  C * A -> C
EndRepeat

where C is the result.
I think that kind of thing would be trivial, but one thing's for sure: don't use the ^ operator for it.
Please note that I don't know Axe.

As Mateo said, exponentiation by squaring is faster, and the algorithm is simple:


Code:
def pow_squaring(base,exp):
    result = 1
    while exp:
        if exp%2: result = base * result
        base = base * base
        exp >>= 1
    return result


However, if you're only dealing with small powers and 8.8 fixed point, exponentiation by repeated multiplication will probably be fast enough.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement