math: x^y

BlitzMax Forums/BlitzMax Programming/math: x^y

taumel(Posted 2005) [#1]
Hi,

is there a math function which can do power of (x^y)?

I know i can make my own function but it would be much nicer if this would be supported by a built in function and i couldn't find it in the docs...


Greetings,

taumel


Tom Darby(Posted 2005) [#2]
Local i, j

i = 4
j = 5

Print	i^j           ' 4^5 = 1024



taumel(Posted 2005) [#3]
Oh man sorry...

Silly me! This happens when you're switching between different tools too fast... :O\


Greetings,

taumel


Tom Darby(Posted 2005) [#4]
Heh. Trust me, you're not alone.


taumel(Posted 2005) [#5]
I always suspected that there have to be other dumb persons beside of me around... ;O)


Greetings,

taumel


Paul "Taiphoz"(Posted 2005) [#6]
yeah like me ;)

dont fret m8 we all do that at times, and just miss the answer even tho its in front of our face, i think its genetic to all programmers.


The r0nin(Posted 2005) [#7]
Correct me if I'm wrong, but I thought Mark had said that x^y was unoptomized at the moment, and so x*x*x*x is faster than x^4. I don't know if a loop adds more overhead than the exponetial function, but if you are using large powers of y, you might want to consider a loop instead...


nawi(Posted 2005) [#8]
well, if its x^2 then you should turn it manually to x*x, but if its x^2.5 then you should leave it like it is.


PGF(Posted 2005) [#9]
Try these:

X ^ 2.5 = X * X * \

X ^ 2.1 = X * X * `

X ^ 1.9 = X * x

Let us know your results :)


Curtastic(Posted 2005) [#10]
Ya x^2 is really slow in blitzmax, I wish it would get optimized because its annoying, and sometimes would run slower to put the same variable twice. Like (player\x-player2\x)^2 versus (player\x-player2\x)*(player\x-player2\x)


bradford6(Posted 2005) [#11]
this is prob the cause of the speed hit:
x:int = 5


x^x:
24.999999999999996

x * x:
25


even if you are asking for the Square of in Integer, the ^ operator returns a Double.

the * operator appears to work with whatever number type you give it


Najdorf(Posted 2005) [#12]
bah, ^ is still so slow? sad :-(
Luckily I didnt have to use it. Anyway sqr() is quite fast and you can always code your own power operator, at least for integer powers.